OutlookEX UDF - Mail Item: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
No edit summary
(No difference)

Revision as of 13:20, 12 May 2012

Here you'll find detailed description if you work with Mail items.

Wrapper functions

The following functions are "wrappers" that combine multiple function calls to mimic functions available in the "original" Outlook UDF.
This should make your scripts a bit shorter and live a bit easier.

SendMail

The wrapper function _OL_Wrapper_SendMail allows to send a mail to multiple recipients (To, Cc and BCc), add attachments, set some properties and send the mail in one go. The body can either be normal text or html. This wrapper function mimics the function of _OutlookSendMail of the original UDF.

Example:

#include <OutlookEx.au3>
$oOL = _OL_Open()
_OL_Wrapper_SendMail($oOL, "John Doe", "", "", "Testmail", "&lt;b>Test&lt;/b>", "", $olFormatHTML, $olImportanceHigh)

This sends a mail to 'John Doe' with Subject 'Testmail', body as HTML and high importance.

Tips & Tricks

Send a mail on behalf of another user

Set property SentOnBehalfOfName to the displayname of the intended sender.

Example:

#include <OutlookEx.au3>
; Open the connection to Outlook
Global $oOL = _OL_Open()
; Create a mail item and set some properties
Global $oItem = _OL_ItemCreate($oOL, $olMailItem, "*\Outlook-UDF-Test\TargetFolder\Mail", "", _
  "Subject=TestMail", "BodyFormat=" & $olFormatHTML, "HTMLBody=Bodytext in &lt;b>Test&lt;/b>.", "SentOnBehalfOfName=Doe Jane")
; Add a recipient and resolve it
_OL_ItemRecipientAdd($oOL, $oItem, Default, $olTo, "Doe John")
; Send the mail
_OL_ItemSend($oOL, $oItem)
If @extended = -2147352567 Then _
  MsgBox(16, "OutlookEX UDF - Example Script", "You don't have permission to send the mail on behalf of the specified person!")

This creates a mail in your folder Outlook-UDF-Test\TargetFolder\Mail, recipient is John Doe, subject is Testmail, body as HTML. SentOnBehalfOfName is set to the displayname of the sender (Jane Doe). The mail is sent and the extended error code is checked if you have the required permissions.

Delay the sending of a mail

Set property DeferredDeliveryTime to date and time when the mail is to be delivered.

Example:

#include <OutlookEx.au3>
; Open the connection to Outlook
Global $oOL = _OL_Open()
; Create a mail item and set some properties
Global $oItem = _OL_ItemCreate($oOL, $olMailItem, "*\Outlook-UDF-Test\TargetFolder\Mail", "", _
  "Subject=TestMail", "BodyFormat=" & $olFormatHTML, "HTMLBody=Bodytext in &lt;b>Test&lt;/b>.", _
  "DeferredDeliveryTime=2017/03/18 18:01:00")
; Add a recipient and resolve it
_OL_ItemRecipientAdd($oOL, $oItem, Default, $olTo, "Doe John")
; Send the mail
_OL_ItemSend($oOL, $oItem)

This creates a mail in your folder Outlook-UDF-Test\TargetFolder\Mail, recipient is John Doe, subject is Testmail, body as HTML. DeferredDeliveryTime is set to 2017/03/18 18:01:00. The mail is sent by Outlook but transmission is deferred by the Exchange server until the specified date/time has been reached.