Sending an email with an attachment is similar to sending an email, with the following additions:

  1. In the POS_FILES$ field, code a value mark delimited list of all the filenames you wish to send, without the path.

  2. In the POS_PATH$ field, code a value mark delimited list of all the filenames you wish to send, with the path.

  3. In the POS_POSITION$ field, enter the length of the message body (in the POS_TEXT$ field) minus 2. This is because the attachment(s) are added to the end of the message body.

Below is sample code to send an email with an attachment (C:\TEST.DOC), with these additions highlighted.

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
   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."
Message<POS_FILES$> = "test.doc"
Message<POS_PATHS$> = "C:\test.doc"
Message<POS_POSITIONS$> = Len(Message<POS_TEXT$>) - 2
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