By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

E-mail Attachments - Mapisend

P: 3
I am facing issues while adding attachments in an E-mail via Mapisend. The code I use is below. If I try to send , I am getting error messgae in Mailmessage.12. Mailmessage.12 is expected as numeric, I do not know what should it be. If I Provide '0', it is throwing out error. Can any one help what shoudl I do to fix this. I am able to send E-mail sucessfully without Attachments..

Code (Please refer comments near Mailmessage.12)

OPTIONS "WINFUNC NOSOURCE C_CALL"
NUMERIC DIGITS 10
/* ============== FUNCDEF some needed OS functions =========== */
DO
/* Register the Windows OS function MAPISendMail(), callable as SendOneEMail */
MapiRecipDesc = "32u, 32u, str *, str *, 32u, void"
MapiMessage = "32u, str *, str *, void, str *, void, 32u, struct MapiRecipDesc *, 32u, struct MapiRecipDesc *, 32u, void"
FUNCDEF("SendOneEMail", "32u, void, void, struct MapiMessage, 32u, 32u", "mapi32", "MAPISendMail")
/* Register the Windows OS function MAPILogon() */
FUNCDEF("MAPILogon", "32u, void, str, str, 32u, 32u, void stor", "mapi32")
/* Register the Windows OS function MAPILogoff() */
FUNCDEF("MAPILogoff", "32u, void, void, 32u, 32u", "mapi32")
CATCH FAILURE
CONDITION("M")
RETURN
END
/* ====================== Send an email ===================== */
/* Log on (to the internet). We need to do this before sending email.
* This will bring up a connection requester for the email
* client if the user is not yet connected to the internet.
* The first arg is a handle to some window you've opened. Omit this
* if you haven't opened a window. If you have no window, then any
* dialog presented (such as a connection dialog) is modal -- that is,
* the user will have to operate it before he can access another program
* on his computer. So, it's best to open a REXX Dialog window and use
* RXQUERY "HANDLE" to get a handle.
** The second arg is a profile name string, limited to 256 characters or
* less. This is the profile to use when logging on. If you omit this
* arg or pass an empty string, and the fourth (flags) arg is not 1,
* then MAPILogon() displays a logon dialog box with an empty name field.
*
* The third arg is the password, limited to 256 characters or less. If
* the messaging system does not require a password, or if it requires
* that the user enter it, then omit this arg or pass an empty string.
* When the user must enter a password, you must add in 1 to the fourth
* arg (flags) to allow a logon dialog box to be displayed.
*
* The fourth arg is a flags (numeric) value. It can be any of the following
* added together:
* * 1 = A logon dialog box should be displayed to prompt for logon information.
* If the user needs to provide information to enable a successful log on,
* this value must be added in.
* 2 = An attempt should be made to create a new session rather than acquire
* the environment's shared session. If this value is not added in, an
* existing shared session is used.
* 8 = Make this a shared session.
* 16 = Don't use the default profile.
* 32 = Extended MAPI Logon.
* 4095 = An attempt should be made to download all of the user's messages
* before returning. If this is not added in, messages may be downloaded in
* the background after the call returns.
* 8192 = Do logon UI in all email accounts.
* 131072 = Display password dialog only.
* 1048576 = Minimal wait for logon.
*
* The fifth arg can be omitted.
* The sixth arg is the name of the REXX variable were you want the MAPI
* "session handle" stored. This will be passed to other MAPI functions.
*/
err = MAPILogon(, , , 1 + 8 + 4095, , Session)
IF err == 0 THEN DO
/* Initialize email structure */
MailMessage.1 = 0
/* Subject line on the email */
MailMessage.2 = "Subject line - Test mail"
/* Email text body. It can be as long as you like, with as many lines as you want */
MailMessage.3 = "Here is the message body of the email" || '0D0A'x || "Line #2"
MailMessage.4 = 0

/* Set the time that the email was sent. The format is Year/2-digit month/2-digit day, * followed by a space, and then Hour:2-digit minute. */
PARSE VALUE TIME('N') WITH hour ':' min ':' .
MailMessage.3 = LEFT(DATE('S'), 2) || DATE('O') hour || ':' || min
MailMessage.5 = LEFT(DATE('S'), 2) || DATE('O') hour || ':' || min

MailMessage.6 = 0

MailMessage.7 = 1 /* Add 2 if a read receipt is requested */

/* Set the originator (ie, the person sending the email) */
MailMessage.8.1 = 0
MailMessage.8.2 = 0
MailMessage.8.3 = "Bambi@com" /* Display name of person sending email */
MailMessage.8.4 = "Bambi@com" /* email address of person sending email */
MailMessage.8.5 = 0
MailMessage.8.6 = 0

/* Set the recipient (ie, the person receiving the email). Note: We send one email, but* you could alternately specify numerous people to which to send the email. You'd have to FUNCDEF the MapiMessage so that the second "struct MapiRecipDesc was actually an array such as "struct MapiRecipDesc[10] *" to send to 10 email addresses. For example, here's how to send the same email to two people:*
* MapiMessage = "32u, str *, str *, void, str *, void, 32u, struct MapiRecipDesc *, 32u, struct MapiRecipDesc[2] *, 32u, void"
*
* MailMessage.9 = 2;
* MailMessage.10.1.1 = 0
* MailMessage.10.1.2 = 1
* MailMessage.10.1.3 = "Jeff Glatt" /* Display name of first person receiving the email */
* MailMessage.10.1.4 = "jglatt@borg.com" /* email address of first person receiving the email */
* MailMessage.10.1.5 = 0
* MailMessage.10.1.6 = 0
* MailMessage.10.2.1 = 0
* MailMessage.10.2.2 = 1
* MailMessage.10.2.3 = "Mr Peabody" /* Display name of second person receiving the email */
* MailMessage.10.2.4 = "someone@somewhere.com" /* email address of second person receiving the email */
* MailMessage.10.2.5 = 0
* MailMessage.10.2.6 = 0
*/
MailMessage.9 = 1;
MailMessage.10.1 = 0
MailMessage.10.2 = 1
MailMessage.10.3 = "Bambi@com" /* Display name of person receiving the email */
MailMessage.10.4 = "Bambi@com" /* email address of person receiving the email */
MailMessage.10.5 = 0
MailMessage.10.6 = 0

/* Count of attached files. We don't send attachments here. If you wanted to send
* attachments, you'd have to FUNCDEF the MapiMessage so that the last void was
* actually an array such of "struct MapiFileDesc *". For example, to send 2 attachments: */

MapiFileDesc = "32u, 32u, 32, str *, void, void"
MapiMessage = "32u, str *, str *, void, str *, void, 32u, struct MapiRecipDesc *, 32u, struct MapiRecipDesc *, 32u, struct MapiFileDesc [2] *"
MailMessage.11 = 0
MailMessage.12.1.1 = 0
MailMessage.12.1.2 = 0
MailMessage.12.1.3 = -1
MailMessage.12.1.4 = "C:\Program Files\Reginald\Rexx\bytsep.txt" /* Full path to first attached file */
MailMessage.12.1.5 = 0
MailMessage.12.1.6 = 0
MailMessage.12.2.1 = 0
MailMessage.12.2.2 = 0
MailMessage.12.2.3 = -1
MailMessage.12.2.4 = "C:\Program Files\Reginald\Rexx\bytsep.txt" /* Full path to second attached file */
MailMessage.12.2.5 = 0
MailMessage.12.2.6 = 0
MailMessage.12 = 0 /***************** I am gettting error because of this parameter */
/* How should this code be converted to add the attachment */

/* Send the email.
*
* First arg is the session handle from MAPILogon.
*
* Second arg is the handle to your window. Omit this if you have no window.
*
* Third arg is the name of the variable that has your initialized MapiMessage struct.
*
* The fourth arg is a flags (numeric) value. It can be any of the following
* added together:
*
* 1 = A logon dialog box should be displayed to prompt for logon information
* if required. If this is not added in, the application does not display a
* logon dialog box and returns an error if the user is not logged on.
*
* 2 = An attempt should be made to create a new session rather than acquire
* the environment's shared session. If this value is not added in, an
* existing shared session is used.
*
* 8 = A dialog box should be displayed to prompt the user for recipients and
* other sending options. If this is not added in, at least one recipient must be
* specified in your MapiMessage struct.
*/
err = SendOneEMail(Session, , MailMessage, 1)
IF err \== 0 THEN SayMAPIErrMessage(err, "Sendmail failed:")

FINALLY
/* Log out
*
* First arg is the session handle from MAPILogon.
*
* Second arg is the handle to your window. Omit this if you have no window. */
MAPILogoff(Session)
END
ELSE SayMAPIErrMessage(err, "Problem logging into MAPI:")

/* Done */
RETURN
SayMAPIErrMessage:
SELECT ARG(1)
WHEN 1 THEN SAY "User aborted."
WHEN 3 THEN SAY "There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed."
WHEN 4 THEN SAY "Can't save attachment because disk is full."
WHEN 5 THEN SAY "Need more memory to send/receive email."
WHEN 6 THEN SAY "Access denied."
WHEN 8 THEN SAY "The user has too many sessions open simultaneously."
WHEN 9 THEN SAY "Too many attachments."
WHEN 10 THEN SAY "Too many recipients."
WHEN 11 THEN SAY "Attachment not found."
WHEN 12 THEN SAY "Can't open an attachment."
WHEN 13 THEN SAY "Can't save an attachment to a temporary file."
WHEN 14 THEN SAY "A recipient did not appear in the address list."
WHEN 15 THEN SAY "Recipient name is specified incorrectly."
WHEN 16 THEN SAY "No messages."
WHEN 17 THEN SAY "Invalid message ID."
WHEN 18 THEN SAY "The text in the message was too large to send."
WHEN 19 THEN SAY "Invalid session."
WHEN 20 THEN SAY "Type not supported."
WHEN 21 THEN SAY "A recipient was specified more than once."
WHEN 22 THEN SAY "Message in use."
WHEN 23 THEN SAY "Network failure."
WHEN 25 THEN SAY "Invalid recipients."
OTHERWISE SAY ARG(2) err
END
RETURN
Nov 1 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.