Mail using SMTP server

This topic provides an example of sending mail using an SMTP server.

MAIN
  DEFINE result, id INTEGER
  DEFINE str STRING

-- first, we initialize the module
  CALL ui.Interface.frontCall("WinMail", "Init", [], [id])

-- Set the body of the mail
  CALL ui.interface.frontCall("WinMail", "SetBody", [id, 
   "This is a text mail using WinMail API - MAPI"], [result])

-- Set the subject of the mail
  CALL ui.interface.frontCall("WinMail", "SetSubject", [id,
   "test mail - ignore it"], [result])

-- Set the mail sender
  CALL ui.Interface.frontCall("WinMail", "SetFrom", [id, "mySelf",
   "me@mycompany.com"], [result])

-- Set the SMTP server
  CALL ui.Interface.frontCall("WinMail", "SetSmtp", [id, "smtp.mycompany.com"],
   [result])

-- Add an Addressee as "TO"
  CALL ui.Interface.frontCall("WinMail", "AddTo", [id, "myBoss",
   "boss@mycompany.com"], [result])

-- Add another Addressee as "BCC"
  CALL ui.Interface.frontCall("WinMail", "AddBCC", [id, "my friend",
   "friend@mycompany.com"], [result])

-- Add Two attachments
  CALL ui.Interface.frontCall("WinMail", "AddAttachment", [id,
   "c:\\mydocs\report.doc"], [result])
  CALL ui.Interface.frontCall("WinMail", "AddAttachment", [id,
   "c:\\mydocs\demo.png"], [result])

-- Send the mail via smtp
  CALL ui.Interface.frontCall("WinMail", "SendMailSMTP", [id], [result])
  IF result == TRUE THEN
    DISPLAY "Message sent successfully"
  ELSE
    CALL ui.Interface.frontCall("WinMail", "GetError", [id], [str])
    DISPLAY str
  END IF
  CALL ui.Interface.frontCall("WinMail", "Close", [id], [result])
END MAIN