OutlookEX UDF - Forward Items

From AutoIt Wiki
Revision as of 12:58, 21 January 2013 by IEvKI3gv9Wrkd41u (talk | contribs) (+Category:OutlookEX_UDF)
Jump to navigation Jump to search

Here you'll find detailed information on how to forward items to other recipients.

Function _OL_ItemForward

Creates a copy of the specified item (contacts, appointments ...) which then can be forwarded to other recipients.
You have to add recipients to this copy of the item (function _OL_ItemRecipientAdd) and then have to use function _OL_ItemdSend to actually send (forward) the item.
If you like you can add some additional text before you forward the item.

Example

This example gets a list of unread mails in the inbox and forwards them to recipient "John.Doe@company.com

; Include Functions
#include <OutlookEX.au3>
Global $oForward, $sRecipient = "John.Doe@company.com"

; Connect to Outlook
Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "Connect to Outlook", "Error connecting to Outlook. @error = " & @error & ", @extended = " & @extended)

; Access correct mailbox
Global $aFolder = _OL_FolderAccess($oOutlook, "\\Correct Mailbox\Inbox", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "Folder access", "Error accessing the mailbox. @error = " & @error & ", @extended = " & @extended)

; Get unread items
Global $aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[UnRead]=True", "", "", "EntryID,Subject,Body")
If @error <> 0 Then Exit MsgBox(16, "Item find", "Error searching for unread mail items. @error = " & @error & ", @extended = " & @extended)
MsgBox(0, "Number of unread items", $aItems[0][0])
If $aItems[0][0] = 0 Then Exit MsgBox(16, "Error", "No mail items in Correct Mailbox Inbox.")

; Forward all unread mails
For $i = 1 To $aItems[0][0]
    $oForward = _OL_ItemForward($oOutlook, $aItems[$i][0], Default, "") ; Create a copy of the item to forward
    If @error <> 0 Then Exit MsgBox(16, "Item forward", "Error creating an item copy to forward. @error = " & @error & ", @extended = " & @extended)
    _OL_ItemRecipientAdd($oOutlook, $oForward, Default, $olTo, $sRecipient) ; Add recipient
    If @error <> 0 Then Exit MsgBox(16, "Recipient add", "Error adding a recipient to the mail item. @error = " & @error & ", @extended = " & @extended)
    _OL_ItemSend($oOutlook, $oForward) ; Send the item to the recipient
    If @error <> 0 Then Exit MsgBox(16, "Item send", "Error sending the mail item. @error = " & @error & ", @extended = " & @extended)
Next

; Close connection to Outlook
_OL_Close($oOutlook)