Guidance
指路人
g.yi.org
Software / Reginald / Examples / sendmail.rex

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* An example of FUNCDEF'ing various Windows OS functions
 * to send an email. This uses simple MAPI, which utilizes
 * whatever email client has been setup on the computer.
 * The new versions of Outlook have security settings that
 * bring up a message box whenever an email is sent. So, for
 * mass mailings, simple MAPI is not suitable. You'd have to
 * use full-blown MAPI.
 */

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"

	/* 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.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 = "Jeff Glatt" /* Display name of person sending the email */
	mailmessage.8.4 = "jglatt@borg.com" /* email address of person sending the 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 = "Jeff Glatt" /* Display name of person receiving the email */
	mailmessage.10.4 = "jglatt@borg.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 = 2
	 * MailMessage.12.1.1 = 0
	 * MailMessage.12.1.2 = 0
	 * MailMessage.12.1.3 = -1
	 * MailMessage.12.1.4 = "C:\MyDir\MyTextFile.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 = "D:\MyProgram.exe" /* Full path to second attached file */
	 * MailMessage.12.2.5 = 0
	 * MailMessage.12.2.6 = 0
	 */
	mailmessage.11 = 0
	mailmessage.12 = 0

	/* 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
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2017-7-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:42