Sending an email with MAPI consists of the following steps:

  1. Logging on to the MAPI Server, using MAPILogon().

  2. Sending the email, using MAPISendMail().

  3. Logging of the MAPI server, using MAPILogoff().

Below is a sample program which sends an email, using the above 3 steps. Note the error testing logic after each function call. Refer to MAPI_Equates for a list of commands and flags that can be sent to the MAPI type functions, and the error codes returned.

 A good test of MAPI functions is to send an email to yourself. Make the From: and To: entries your email address. Then see if, after you run the program, the email shows up in your in box.

Depending on your email settings, the login dialog may display whether or not you have set the MAPI_LOGON_UI$ flag. For example, there is a security setting in Microsoft Outlook Express that forces the login dialog to display. Each email environment is different. Check with your email administrator.

declare function MAPILogon , MAPISendMail, MAPILogoff
declare subroutine msg, get_status
$insert MAPI_Equates
 
session = ''
parent = @window
user = ''
password = ''
 
// Logon to MAPI with prompt
if MAPILogon (session, @window,user, password, MAPI_LOGON_UI$ + MAPI_NEW_SESSION$)  then
/*
  Note:  if you know the profile (such as Outlook Internet Settings) to log into the mail system, call MapiLogon() as shown below
  if MAPILogon (session, @window , 'Outlook Internet Settings', '') then
*/
      Msg(@window, "Mail login successful!")
End Else
  Get_Status(ErrMsg)
  Msg(@window, ErrMsg)
End
 
// Send an email, requesting a receipt.
Flags = MAPI_RECEIPT_REQUESTED$ + MAPI_DIALOG$ + MAPI_NEW_SESSION$
Message = ''
Message<POS_SUBJECT$> = "Send e-mail Test"
Message<POS_TO$>          = "marketing@yourcompany.com"
Message<POS_FROM$>     =  "info@revelation.com"
Message<POS_TEXT$>      = "This is a sample Message"
Message<POS_FLAGS$>   = Flags
Message<POS_TYPE$>       = "IPM.Microsoft Mail.Note"
If MAPISendMail(session, @window, Flags, Message) then
  * Msg(@window, "Message sent successfully!")
End Else
  Get_Status(ErrMsg)
  Msg(@window, ErrMsg)
End
 
// Logoff from MAPI
if MAPILogoff(session) then
   Msg(@window, "Logoff successful")
end else
   Get_Status(display)
   Msg(@window, display)
end
  • No labels