Jump to content

OutlookEX UDF - Help & Support


Recommended Posts

Based on the information I have I would suggest to search for items with attachments, then get the list of attachments for each item and search for PDF files. If found do whatever you like.

sorry. I thought that's what I was doing. obviously not!

I'm showing my inexperience here - could you point me in the right direction?

Link to comment
Share on other sites

The following example writes the subject of every mail from the Inbox with an attachment plus all attachment names to the console.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#AutoIt3Wrapper_Au3Check_Stop_OnWarning=Y
#include <OutlookEX.au3>
#include <Array.au3>
HotKeySet("+!e", "_Exit") ;Shift-Alt-E to Exit the script
MsgBox(64, "OutlookEX UDF Example Script", "Hotkey to exit the script: 'Shift-Alt-E'!")
Global $oOApp = ObjCreate("Outlook.Application")
Global $oOFolder = $oOApp.GetNamespace("MAPI").GetDefaultFolder($olFolderSentMail).Items
Global $test = ObjEvent($oOFolder, "oOFolder_")
Global $var = ""
Global $SaveEmail
While 1
WEnd
Func oOFolder_ItemAdd($oOL_Item)
$SaveEmail = MsgBox(4, "TMR - Save Sent Email", "Do you want to Save the Email?")
If $SaveEmail = "6" Then
  Global $oOutlook = _OL_Open()
  ; Select location to save email to
  $var = FileSelectFolder("Select the Matter", "h:Client Files all2010")
  ; Save email
  _OL_ItemSave($oOutlook, $oOL_Item, Default, $var & "" & "EML.SUBJECT-" & $oOL_Item.Subject & ".SENDER-" & $oOL_Item.SenderName & ".TO-" & $oOL_Item.To & ".SENT-" & $oOL_Item.SentOn & ".", $olMSG)
  If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_Itemsave", "Error saving specified emails. @error = " & @error & ", @extended = " & @extended)
  ; Move email to archive
  _OL_ItemMove($oOutlook, $oOL_Item, Default, "*TMR - Sent and Saved")
  If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove", "Error moving specified emails. @error = " & @error)
  MsgBox(64, "OutlookEX UDF: _OL_ItemMove", "Emails successfully Saved to " & $var)
  _OL_Close($oOutlook)
EndIf
EndFunc   ;==>oOFolder_ItemAdd
Func _Exit()
Exit
EndFunc   ;==>_Exit

Water:

You will recall the above code that detects when a new email is added to the Sent Items folder and then triggers the happening of certain events. It works very well. However, if outlook is closed, the connection to the script is severed and the trigger no longer works unless the script is restarted. Do you have any suggestion on how to make the trigger more persistent so that the opening and closing of Outlook does not cause the trigger to fail?

I had considered some sort of check within the While command that would cause the script to restart if outlook was closed, but I am not sure if this is the best approach or not.

Any help will be most greatly appreciated.

SkoubyeWan

Link to comment
Share on other sites

As a follow up to my most recent post, I tried the following which restarts the script whenever Outlook exits. Seems to work . . . but would hope for something better:

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
While 1
If WinWaitClose("Microsoft Outlook") Then
  Run("D:DataAutoIT ScriptsTMR - Save Sent Emails to TMR and Move from Sent Items.exe")
  Exit
EndIf
WEnd
Link to comment
Share on other sites

You have to handle the situation that your script is beeing closed and that Outlook or the PC are beeing shutdown. Mails that arrive during that time are not handled by the script even when being restarted.

You need to insert some code at the begin of the script that uses _OL_ItemFind and then processes the found items the way you now do for items that trigger the event.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You have to handle the situation that your script is beeing closed and that Outlook or the PC are beeing shutdown. Mails that arrive during that time are not handled by the script even when being restarted.

You need to insert some code at the begin of the script that uses _OL_ItemFind and then processes the found items the way you now do for items that trigger the event.

The script is still running. It is the closing of outlook that seems to disconnect the trigger. The restarting of the script after the closing of outlook re-initiates the trigger, even if outlook is not reoppened.

The solution I posted before is working. It restarts the script whenever outlook is closed, so that the trigger fires whenever an email is saved to the "Sent Items" folder, outlook open or not.

SkoubyeWan

Link to comment
Share on other sites

That's true because ObjCreate starts Outlook if it isn't already running. ObjCreate is _OL_Open stripped down.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

func _DoForwardMail($UnreadMailID,$to,$cc)
  ;the string, i don`t want to add in the Subject , i want to add in the BODY
  _OL_raymond_ForwardMail($oOutlook,$UnreadMailID,"Hello everybody, There is a warning mail,Please Check it ,Thanks!!!", $to, $cc, "")
  If @error <> 0 Then Exit MsgBox(16, "EMAIL Wrong", "Send Mail faild!!Please Do again!!ERROR="&@error)
endfunc

Func _OL_raymond_ForwardMail($oOL,$oOL_Item,$addSubject, $sTo = "", $sCc = "", $sBCc = "")
If $sTo = "" And $sCc = "" And $sBCc = "" Then SetError(3, 0, 0)
;get the forwarded item
$oOL_Item=_OL_ItemForward($oOutlook,$oOL_Item, Default,0)
If @error <> 0 Then Return SetError(@error + 3000, @extended, 0)
;Modify the subject. (I have no idea.so i modify the subject)
Local $aOL_Subject = _OL_ItemGet($oOutlook, $oOL_Item,Default,"Subject")
If @error <> 0 Then Return SetError(@error + 3000, @extended, 0)
If UBound($aOL_Subject)=2 Then
  $aOL_Subject=$aOL_Subject[1][1]
Else
  Return SetError(@error + 3000, @extended, 0)
EndIf
;Modify the sendername,because the mailOwner is not me . i don`t have the "SendAs" power
_OL_ItemModify($oOutlook, $oOL_Item, Default, "Subject="&$addSubject&$aOL_Subject,"SenderName= ","SentOnBehalfOfName= ")
If @error <> 0 Then Return SetError(@error + 3000, @extended, 0)
;add the Recipients
Local $aOL_Recipients
If $sTo <> "" Then
  $aOL_Recipients = StringSplit($sTo, ";", 2)
  _OL_ItemRecipientAdd($oOL, $oOL_Item, Default, $olTo, $aOL_Recipients)
  If @error <> 0 Then Return SetError(@error + 4000, @extended, 0)
EndIf
If $sCc <> "" Then
  If @error <> 0 Then Return SetError(@error + 4000, @extended, 0)
  $aOL_Recipients = StringSplit($sCc, ";", 2)
  _OL_ItemRecipientAdd($oOL, $oOL_Item, Default, $olCC, $aOL_Recipients)
  If @error <> 0 Then Return SetError(@error + 4000, @extended, 0)
EndIf
If $sBCc <> "" Then
  If @error <> 0 Then Return SetError(@error + 4000, @extended, 0)  
  $aOL_Recipients = StringSplit($sBCc, ";", 2)
  _OL_ItemRecipientAdd($oOL, $oOL_Item, Default, $olBCC, $aOL_Recipients)
  If @error <> 0 Then Return SetError(@error + 4000, @extended, 0)
EndIf
; i have no idea about the Modify HTMBody , i use _OL_ItemGet the HTMLBody and Body .i find it is empty.
;_OL_ItemModify($oOutlook, $oOL_Item, Default, "HTMLBody=HHJJJJDDDDDJJSJSJSJSJ")
;If @error <> 0 Then Return SetError(@error + 8880, @extended, 0)

; Send mail
;Global $aOL_Properties = _OL_ItemGet($oOL, $oOL_Item)
;_ArrayDisplay($aOL_Properties)
_OL_ItemSend($oOL, $oOL_Item, Default)
If @error <> 0 Then Return SetError(@error + 6000, @extended, 0)
Return $oOL_Item
EndFunc   ;==>_OL_raymond_ForwardMail

hi water.

i have no idea about the Modify HTMBody , i use _OL_ItemGet the HTMLBody and Body .i find it is empty.

in the forward mailitem `s Body, i want to add some string In the above.

can help me?,thanks water.!!!!!

The format of a mail (text, html, rich-text) is defined in property "BodyFormat" and set to a value of the OlBodyFormat enumeration.The clear-text body of a mail is stored in property "Body", the HTML-body is stored in property "HTMLBody". Check the value of the "BodyFormat" enumeration. If it is not set to OlFormatHTML (integer value: 2) then you have to set this porperty to OlFormatHTML and copy the content of property "Body" to "BodyHTML". Now you can add some text.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

i have checked BodyFormat ,the values is 2 .and the values of "Body" is right.

but i can not copy the content of property "Body" to "HTMLBody".

it is no error ,but the values of "HTMLBody" is also empty .

Local $aOL_mybody = _OL_ItemGet($oOL, $oOL_Item,Default,"Body")
_ArrayDisplay($aOL_mybody)
If UBound($aOL_mybody)=2 Then
  Local $aOL_mybody22=$aOL_mybody[1][1]
Else
  Return SetError(@error + 3000, @extended, 0)
EndIf
ConsoleWrite($aOL_mybody22)
_OL_ItemModify($oOL, $oOL_Item, Default, "HTMLBody="&$aOL_mybody22)
If @error <> 0 Then Return SetError(@error + 8881, @extended, 0)

$aOL_Properties111 = _OL_ItemGet($oOL, $oOL_Item)
_ArrayDisplay($aOL_Properties111)
Link to comment
Share on other sites

If the value of BodyFormat is 2 then the body of the mail should be retrieved from property HTMLBody.

Do you use the object returned by _OL_ItemForward to modify the mail?

_OL_ItemForward creates a copy of the original mail which you then need to send using _OL_ItemSend.

The issue was discussed some time ago in this

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I had a quick check using Google but didn't find any problems with forwarding an email. Will have to check it tomorrow when I'm in my office again.

What version of Outlook do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi wokao98,

just a small change in function _OL_ItemForward in version 0.6.0. Replace line$oOL_Item.Close(0)with$oOL_Item.Save()

Before you move to version 0.7.1.1 be sure to check that your script works with Outlook 2007. Here with Outlook 2010 the script or even Outlook crashes when I try to send a forwarded item.

Will have to investigate ...

Please replace function _OL_ItemForward in your UDF with this version:

Func _OL_ItemForward($oOL, $vOL_Item, $sOL_StoreID, $iOL_Type)

    Local $vOL_ItemForward
    If Not IsObj($vOL_Item) Then
        If StringStripWS($vOL_Item, 3) = "" Then Return SetError(1, 0, 0)
        $vOL_Item = $oOL.Session.GetItemFromID($vOL_Item, $sOL_StoreID)
        If @error Then Return SetError(2, @error, 0)
    EndIf
    ; Mail: Simple forward
    ; Appointment: ForwardAsVcal
    ; Contact: ForwardAsVcal (Outlook 2002 as Vcard) or ForwardAsBusinessCard
    If $vOL_Item.Class = $olMail Then
        If $vOL_Item.Sent = False Then Return SetError(5, 0, 0)
        $vOL_ItemForward = $vOL_Item.Forward
    ElseIf $vOL_Item.Class = $olContact Then
        If $iOL_Type = 1 Then
            If $vOL_Item.OutlookVersion = "10.0" Then
                $vOL_ItemForward = $vOL_Item.ForwardAsVcard
            Else
                $vOL_ItemForward = $vOL_Item.ForwardAsVcal
            EndIf
        EndIf
        If $iOL_Type = 2 Then $vOL_ItemForward = $vOL_Item.ForwardAsBusinessCard
    Else
        $vOL_ItemForward = $vOL_Item.ForwardAsVcal
    EndIf
    If @error Then Return SetError(3, @error, 0)
    $vOL_ItemForward.Save()
    If @error Then Return SetError(4, @error, 0)
    Return $vOL_ItemForward

EndFunc   ;==>_OL_ItemForward
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

hi water,sorry for my bad english

how strange it was.

i have replace function _OL_ItemForward.

but it is not OK.see the Screenshot.

when i use the "_OL_ItemModify($oOL, $oOL_Item, Default, "HTMLBody=AddString"&$aOL_mybody22) "

and Sent. the old html style have change.

post-68974-0-12563600-1335827718_thumb.j

i hope to like it.

post-68974-0-78473400-1335827739_thumb.j

Edited by wokao98
Link to comment
Share on other sites

At least you can now see the content of the Body and HTMLBody properties? Good.

I had a look at property HTMLBody of one of my mails. It has a lot of header information at the beginning. I fear to manually add some text before this header information might give you the undesired result.

To make sure that the resulting HTML formats properly you need to search for the correct position in the HTML "stream" and insert your HTML text.

An minimum HTML document looks like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Beschreibung der Seite</title>
</head>
<body>
</body>
</html>

So you need to search for "<body>" and insert your text after this tag.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water - hoping you can help... again!

I have my Outlook Forward emails script working well on XP, however when I run it on Windows 7 I get a 'Subscript used with non-Array variable' error. The error points to line 168. I've posted my code below in the hope you can point out the problem.

Many thanks in advance

#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
; Include Functions
#include <OutlookEX.au3>
#include <OutlookEXConstants.au3>
#include <GUIconstants.au3>
Global $oForward
Global $oForward1
Global $oMove
Global $oSendTo
Global $oSendToSwitch
Global $Doc = "1@1.com"
Global $DCS = "2@2.com"
Global $radioval1
Global $radioval2
Global $radio_1
Global $radio_2
Global $button_1
Global $msg
Global $aAttachments

Msgbox(48, "Action Required", "Ensure all emails to be forwarded are marked with the 'Auto IT' category" & @CRLF & @CRLF & "then click 'Ok'")
;*************
;* GUI Start *
;*************
Opt("GUIcoordMode", 1)
GUICreate("Scanning Provider...", 190, 160)
; Create the controls
$button_1 = GUICtrlCreateButton ("Ok", 30, 85, 120, 35)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio ("Documetric", 50, 25, 100, 20)
$radio_2 = GUICtrlCreateRadio ("DCS", 50, 50, 100, 20)
; Set the defaults (radio buttons clicked, default button, etc)
GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON)
; Init our vars that we will use to keep track of radio events
$radioval1 = 0
$radioval2 = 2
GUISetState ()
While 1
  $msg = GUIGetMsg()
  Select
      Case $msg = $GUI_EVENT_CLOSE
        SplashTextOn("Exiting", "Exiting the script.  Please re-run", 190, 100, -1, -1, 4, "", -1, 1000)
  Sleep(1500)
  SplashOff()
  Exit
      Case $msg = $button_1
        If GUICtrlRead($radio_1) = $GUI_CHECKED Then
            $oSendTo = $Doc
   $oSendToSwitch = 2
   ExitLoop
            ;close gui here
        ElseIf GUICtrlRead($radio_2) = $GUI_CHECKED Then
            $oSendTo = $DCS
   $oSendToSwitch = 1
   ExitLoop
            ;close gui here
        Else
            MsgBox(16,"Please try again", "No scanning provider has been selected")
            Sleep(2500)
            ContinueLoop
        EndIf
      Case $msg = $radio_1 OR $msg = $radio_2
        $radioval1 = $msg - $radio_1
  EndSelect
WEnd
GUIDelete()
;***********
;* GUI End *
;***********
; 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 MailboxInbox", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "Folder access", "Error accessing Correct MailboxInbox. @error = " & @error & ", @extended = " & @extended)
;*************************************
;* Search for items with attachments *
;*************************************
Global $sFilter = "@SQL=(""urn:schemas:httpmail:hasattachment"" = 1)"
Global $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $sFilter, "EntryID,subject")
If @error Then
    MsgBox(16, "Searching", "Error Searching Correct MailboxInbox. @error = " & @error & ", @extended = " & @extended)
Exit
Else
    traytip("Searching", "Searching for non-PDF attachments and marking them with the 'Non-PDF' category", 30, 1)
Sleep(2000)
EndIf
; Now get a list of attachments
For $i = 1 To $aResult[0][0]
ConsoleWrite($aResult[$i][1] & @CRLF)
$aAttachments = _OL_ItemAttachmentGet($oOutlook, $aResult[$i][0])
For $j = 1 To $aAttachments[0][0]
  ;ConsoleWrite("  " & $aAttachments[$j][2] & @CRLF)
  If StringRegExp($aAttachments[$j][2], "pdf$") Then
   ConsoleWrite("  " & $aAttachments[$j][2] & @CRLF)
  Else
   consolewrite("  not a pdf" & @CRLF)
   ;Set 'Non-PDF' category
   _OL_ItemModify($oOutlook, $aResult[$i][0], Default, "Categories=Non-PDF" )
   If @error <> 0 Then Exit MsgBox(16, "Update Category", "Error marking item with 'Non-PDF' category. @error = " & @error & ", @extended = " & @extended)
  EndIf
Next
Next
; Get emails with AutoIT category items
Global $aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[Categories]=AutoIT", "", "", "EntryID,Subject,Body")
If @error <> 0 Then Exit MsgBox(16, "Item find", "Error searching for mail items with 'AutoIT' category. @error = " & @error & ", @extended = " & @extended)
;Error if no emails with AutoIT category
If $aItems[0][0] = 0 Then Exit MsgBox(16, "Error", "No mail items with 'AutoIT' category in Correct Mailbox 'Inbox' folder.")
Traytip("Working...", "Starting up......", 30, 1)
Sleep(1000)
; Forward 'AutoIT' category emails to selected supplier
For $i = 1 To $aItems[0][0]
;Create a copy of the item to forward
    $oForward = _OL_ItemForward($oOutlook, $aItems[$i][0], Default, "")
    If @error <> 0 Then Exit MsgBox(16, "Item forward", "Error creating an email copy to forward. @error = " & @error & ", @extended = " & @extended)
;Add recipient
    _OL_ItemRecipientAdd($oOutlook, $oForward, Default, $olTo, $oSendTo)
    If @error <> 0 Then Exit MsgBox(16, "Recipient add", "Error adding a recipient to the mail item. @error = " & @error & ", @extended = " & @extended)
    ;Send
_OL_ItemSend($oOutlook, $oForward)
    If @error <> 0 Then Exit MsgBox(16, "Item send", "Error sending the mail item. @error = " & @error & ", @extended = " & @extended)
    $oForward.Display
;Get year and month for correct folder
Global $YearMon = @YEAR & "-" & @MON
;Get details on folder that email will be moved to
  Global $aFolder1 = _OL_FolderAccess($oOutlook, "Correct MailboxInboxInvoices sent to Supplier2" & $YearMon, $olFolderInbox)
Global $aFolder2 = _OL_FolderAccess($oOutlook, "Correct MailboxInboxInvoices sent to Supplier1" & $YearMon, $olFolderInbox)
;Mark as Read and set 'AutoIT' category
_OL_ItemModify($oOutlook, $aItems[$i][0], Default, "UnRead=False")
If @error <> 0 Then Exit MsgBox(16, "Mark as Read", "Error marking item as Read. @error = " & @error & ", @extended = " & @extended)
;Move item
If $oSendToSwitch = 1 Then
  ;Move to Supplier2
  _OL_ItemMove($oOutlook, $aItems[$i][0], Default, $aFolder1[1])
  If @error <> 0 Then MsgBox(16, "Item move", "Error moving the mail item.  Check the folder 'Correct MailboxInboxInvoices sent to Supplier2" & $YearMon &"' exists. " & @error & " @extended = " & @extended)
Else
  ;Move to Supplier1
  _OL_ItemMove($oOutlook, $aItems[$i][0], Default, $aFolder2[1])
  If @error <> 0 Then MsgBox(16, "Item move", "Error moving the mail item.  Check the folder 'Correct MailboxInboxInvoices sent to Supplier1" & $YearMon &"' exists. " & @error & " @extended = " & @extended)
EndIf
Traytip("Working...", "Sending email " & $i & " of " & $aItems[0][0] & " to " & $oSendTo, 30, 1)
Next
Traytip("Emails Sent", "All emails should now have been sent to " & $oSendTo & " and moved to the correct storage folder", 30, 1)
Sleep(2500)
;check if there are any emails with Non-PDF attachments and give opportunity to send if desired
Traytip("Checking", "Checking for Non-PDF attachments", 30, 1)
Sleep(2500)
Global $aItems1 = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[Categories]=Non-PDF", "", "", "EntryID,Subject,Body")
If @error <> 0 Then Exit MsgBox(16, "Item find", "Error searching for mail items with 'Non-PDF' category. @error = " & @error & ", @extended = " & @extended)
If $aItems1[0][0] = 0 Then
Traytip("No Non-PDF attachments", "No emails with the 'Non-PDF' category were found.  Exiting in 5 seconds", 5, 1)
Sleep(5000)
Exit
EndIf
; Give opportunity to send Non-PDF invoices to Documetric
Traytip("Non-PDF attachments", "Non-PDF attachments found", 30, 1)
If msgbox(4+32, "Send Non-PDF invoices to " & $Doc & "?", "Do you want to send the Non-PDF invoices to " & $Doc & "?") = 7 Then ; 7 = 'No' selected
Traytip("Emails Sent", "All emails should now have been sent to " & $oSEndTo & " and moved to the correct storage folder" & @CRLF & @CRLF & "Exiting in 5 seconds" , 4, 1)
Sleep(5000)
Exit
Else ; 6 = 'Yes' selected
; Forward Non-PDF category emails to selected supplier
For $j = 1 To $aItems1[0][0]
  ;Create a copy of the item to forward
  $oForward1 = _OL_ItemForward($oOutlook, $aItems1[$j][0], Default, "")
  If @error <> 0 Then Exit MsgBox(16, "Item forward", "Error creating an item copy to forward. @error = " & @error & ", @extended = " & @extended)
  ;Add recipient
  _OL_ItemRecipientAdd($oOutlook, $oForward1, Default, $olTo, $Doc)
  If @error <> 0 Then Exit MsgBox(16, "Recipient add", "Error adding a recipient to the mail item. @error = " & @error & ", @extended = " & @extended)
  ;Send
  _OL_ItemSend($oOutlook, $oForward1)
  If @error <> 0 Then Exit MsgBox(16, "Item send", "Error sending the mail item. @error = " & @error & ", @extended = " & @extended)
  $oForward.Display
  ;Mark as Read
  _OL_ItemModify($oOutlook, $aItems1[$j][0], Default, "UnRead=False")
  If @error <> 0 Then Exit MsgBox(16, "Mark as Read", "Error marking item as Read. @error = " & @error & ", @extended = " & @extended)
  ;Move to Supplier 1
  _OL_ItemMove($oOutlook, $aItems1[$j][0], Default, $aFolder2[1])
  If @error <> 0 Then MsgBox(16, "Item move", "Error moving the mail item.  Check the folder 'Correct MailboxInboxInvoices sent to Supplier1" & $YearMon &"' exists. " & @error & " @extended = " & @extended)
  Traytip("Working...", "Sending email " & $j & " of " & $aItems1[0][0] & " to " & $Doc, 30, 1)
Next
EndIf
Traytip("Emails Sent", "All emails should now have been sent to " & $Doc & " and moved to the correct storage folder" & @CRLF & @CRLF & "Exiting in 5 seconds" , 4, 1)
Sleep(5000)

Sorry - forgot to mention i'm on Outlook 2010 as well, which may be the problem.

Edited by mdcastle
Link to comment
Share on other sites

@wokao98

My understanding is that if you work with an HTML formated mail property BodyFormat is set to 2, property HTMLBody contains the mail plus all HTML tags and property Body only contains the mail text without any formating.

If you change HTMLBody then Body will be changed immediately (according to MS).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@mdcastle

Do you run a compiled exe or from within SciTe? Line number 168 has to be somewhere in the OutlookEX UDF.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...