Results 1 to 3 of 3

Thread: Using Outlook to send emails

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658

    Using Outlook to send emails

    Hello,

    There have been several discussions on how to send email from Lianja, such as
    http://www.lianja.com/community/show...ough-gmail-SSL

    Also mentioned was a built in email function called sendmail.
    http://www.lianja.com/doc/index.php/SENDMAIL()

    Some issues that I noticed with sendmail include:
    - knowing the smtp server address, username and password;
    - determining if you need to use SMTP or ESTMP protocols;
    - there is no record of a sent message;
    - there is no notification for undelivered message

    If you prefer to worry less about the details, you can use Microsoft Outlook to send/track emails.
    Here is some basic code that seemed to work for me (using Windows 7).
    This code should work regardless if Outlook is open/active or not.

    Code:
    emailAttach = getfile()
    LOCAL loOutlook   AS Outlook.Application
    LOCAL loNameSpace AS Outlook.NameSpace 
    LOCAL loNewMsg    AS Outlook.MailItem
    	
    #DEFINE olMailItem   0
    	
    loOutlook = CREATEOBJECT('Outlook.Application')
    loNameSpace = loOutlook.GetNameSpace("MAPI")
    loNameSpace.SendAndReceive(.T.)
    loNewMsg = loOutlook.CreateItem(olMailItem)
    loNewMsg.Attachments.Add(emailAttach)
    loNewMsg.Subject = "This is the subject"
    loNewMsg.Body = "Some information here."
    
    loNewMsg.To = "abc@test.com;cba@test.com"
    loNewMsg.CC = "info@test.com"
    loNewMsg.Recipients.ResolveAll()
    loNewMsg.Send()
    Enjoy.

    Cory

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Location
    Rome - Italy
    Posts
    1,877
    Thank you Cory to share this code.

    Fabio

  3. #3
    Member
    Join Date
    May 2012
    Posts
    37
    Possible downsides of MAPI:

    Using MAPI like that won't use any stationery/signature that outgoing emails normally use.
    Outlook security on a customer PC could well pop up a 'A program is trying to send a message on your behalf' warning that you have to click to close for each send(), which is fun when you're doing a batch of 500.
    It'll only work on Windows machines with Outlook installed.

    For those reasons I would always use SMTP even if it is more difficult to set up initially. But it's a use-case thing of course.

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us