SkoubyeWan Posted April 24, 2012 Share Posted April 24, 2012 SkoubyeWan, here is the enhanced version (untested). It could be enhanced further so that _OL_ItemGet doesn't return all properties of the mail item but just the few you need. This has the advantage that your script will run with future versions of Outlook - just in case that the number of the properties and hence the position in the array changes. I get the following properties (Outlook 2010/Exchange 2010): 51 - ReceivedOnBehalfOfEntryID 66 - RTFBody 74 - Sensitifity 80 - Subject expandcollapse popup#AutoIt3Wrapper_Au3Check_Stop_OnWarning=Y #include <outlookex.au3> #include <array.au3> ; ***************************************************************************** ; Example Script ; Handle Outlook ItemSend event when an item is sent allowing the item to be saved in msg format to the hard drive and then moved to an archive folder. ; This script loops until Shift-Alt-E is pressed to exit. ; ***************************************************************************** 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 $oEvent = ObjEvent($oOApp, "oOApp_") Global $sFolder = "", $iSaveEmail, $aOL_Properties While 1 WEnd ;~ ; Outlook 2007 - ItemSend event - http://msdn.microsoft.com/en-us/library/bb147641%28v=office.12%29.aspx Func oOApp_ItemSend($sOL_ItemObject, $bOL_Cancel) #forceref $bOL_Cancel $iSaveEmail = MsgBox(4, "TMR - Save Sent Email", "Do you want to Save the Email?") If $iSaveEmail = 6 Then $sFolder = FileSelectFolder("Select the location to save to", "h:") If @error <> 1 Then ; User cancels/closes the file selection window $aOL_Properties = _OL_ItemGet($oOApp, $sOL_ItemObject) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemGet Example Script", "Error accessing properties. @error = " & @error & ", @extended = " & @extended) _OL_ItemSave($oOApp, $sOL_ItemObject, Default, $sFolder & "" & "EML.SUBJECT-" & $aOL_Properties[74][1] & ".SENDER-" & $aOL_Properties[66][1] & ".TO-" & $aOL_Properties[80][1] & ".RECEIVED-" & $aOL_Properties[51][1] & ".", $olMSG) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_Itemsave", "Error saving specified emails. @error = " & @error & ", @extended = " & @extended) _OL_ItemMove($oOApp, $sOL_ItemObject, Default, "*TMR - Sent and Saved") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove", "Error moving specified emails. @error = " & @error & ", @extended = " & @extended) EndIf EndIf EndFunc ;==>oOApp_ItemSend Func _Exit() Exit EndFunc ;==>_Exit Thanks. This will be much better. I am receiving the following errror however that you might be able to help me decypher. >Running:(3.3.8.1):C:Program FilesAutoIt3autoit3.exe "D:DataAutoIT ScriptsTMR - Save Sent Emails to TMR and Move from Sent Items.au3" C:\Program Files\AutoIt3\Include\OutlookEX.au3 (2590) : ==> The requested action with this object has failed.: Local $aOL_Properties[$vOL_Item.ItemProperties.Count + 1][3] = [[$vOL_Item.ItemProperties.Count, 3]] Local $aOL_Properties[$vOL_Item.ItemProperties^ ERROR ->06:10:38 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 33.179 Link to comment Share on other sites More sharing options...
water Posted April 24, 2012 Author Share Posted April 24, 2012 Error 13 stands for: No records returned by the search operation I don't think you can specify property "attachmentfilename" in a DASL query. I will do some further investigation ... 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 More sharing options...
water Posted April 24, 2012 Author Share Posted April 24, 2012 SkoubyeWan, there seems to be a problem with the object passed. I need to do some further investigation ... 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 More sharing options...
water Posted April 24, 2012 Author Share Posted April 24, 2012 (edited) SkoubyeWan,At least I have found the reason why your script crashes.The event is fired before the mail is sent and hence the properties have not been set.The solution seems to be the event that is fired when the mail is saved to the "Sent Item" folder. I will have to come up with a working example. Stay tuned ... Edited April 24, 2012 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 More sharing options...
SkoubyeWan Posted April 24, 2012 Share Posted April 24, 2012 SkoubyeWan, At least I have found the reason why your script crashes. The event is fired before the mail is sent and hence the properties have not been set. The solution seems to be the event that is fired when the mail is saved to the "Sent Item" folder. I will have to come up with a working example. Stay tuned ... I dealt with this issue as well with my script. I used the following, though it is not elegant: $SentFolderInfo = _OL_FolderGet($oOutlook, "*Sent Items") $SentItemsNumberBefore = $SentFolderInfo[8] While $SentItemsNumberBefore = $SentFolderInfo[8] $SentFolderInfo = _OL_FolderGet($oOutlook, "*Sent Items") WEnd This keeps the script from running until after the number of items in the Sent Items folder is changed. Again, not elegant. Hopefully there is a better solution Link to comment Share on other sites More sharing options...
water Posted April 24, 2012 Author Share Posted April 24, 2012 OK, this should work now. The script fires an event when a new mail arrives in the "Sent Items" folder. It then shows 4 properties of the item: Subject, SenderName, To, Received. Be sure to specify only needed properties. It crashes here (Outlook 2010) when I list all properties. When you expand it for your purposes make sure that: You check the item type so you only process mails; you check the subject or whatever so you only process mails you really want to archive ... 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 More sharing options...
SkoubyeWan Posted April 24, 2012 Share Posted April 24, 2012 OK, this should work now. The script fires an event when a new mail arrives in the "Sent Items" folder. It then shows 4 properties of the item: Subject, SenderName, To, Received.Be sure to specify only needed properties. It crashes here (Outlook 2010) when I list all properties.When you expand it for your purposes make sure that: You check the item type so you only process mails; you check the subject or whatever so you only process mails you really want to archive ...Thanks. I will take a look at this soon and get back with you. Having the trigger be the adding of an item to the Sent Items folder is the right way to handle this.SkoubyeWan Link to comment Share on other sites More sharing options...
SkoubyeWan Posted April 24, 2012 Share Posted April 24, 2012 OK, this should work now. The script fires an event when a new mail arrives in the "Sent Items" folder. It then shows 4 properties of the item: Subject, SenderName, To, Received. Be sure to specify only needed properties. It crashes here (Outlook 2010) when I list all properties. When you expand it for your purposes make sure that: You check the item type so you only process mails; you check the subject or whatever so you only process mails you really want to archive ... Water: I can't thank you enough! That worked great. Here is the script based upon your event. It captures when an email is placed in the Sent Items folder and asks the user if he or she wants to save the item. It then saves the item in a directory of their choice and moves the email to an archive folder. Hope this is useful to others. It certainly is to me. #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 Link to comment Share on other sites More sharing options...
hazed Posted April 24, 2012 Share Posted April 24, 2012 First, I might have missed this somewhere or I just don't get how to point to a certian mailbox, but What I'm trying to do is create a rule to run against a Shared Mailbox. Under my profile, I have 3 mailboxes, I want to create a rule to get all new mail in the mailbox and "process the requests". I can't seem to beable to figuire out how to get the folder infomation from the second mailbox. Link to comment Share on other sites More sharing options...
water Posted April 24, 2012 Author Share Posted April 24, 2012 Do you want to check for new email in a loop or do you want a script that waits for a new mail to arrive and then call a function? 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 More sharing options...
mdcastle Posted April 25, 2012 Share Posted April 25, 2012 waterFurther to my request for help searching for attachment types i've been googling and i'm wondering if the PR_SEARCH_ATTACHMENTS property could be utilised in $avOL_Search? I'm fishing here as i'm not even sure if the filename extension would be included here.The section on searching attachments at http://msdn.microsoft.com/en-us/library/cc513841.aspx gives a C# example of how it could be done, but i'm stuck on how to change the search string to be used with $sFilter. Link to comment Share on other sites More sharing options...
water Posted April 25, 2012 Author Share Posted April 25, 2012 Hi mdcastle,I understand the link you provided that you can search the content of attachments but not for the name of attachments:"PR_SEARCH_ATTACHMENTS property.This property causes Outlook to evaluate the search criteria against the contents of item attachments."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. 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 More sharing options...
mdcastle Posted April 25, 2012 Share Posted April 25, 2012 Ok so i've changed my code to $sFilter = "@SQL=(""urn:schemas:httpmail:hasattachment"" = 1)" $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $sFilter, "http://schemas.microsoft.com/mapi/proptag/0x3707001E") to get PR_ATTACH_LONG_FILENAME as per http://stackoverflow.com/questions/4657684/nicely-reading-outlook-mailitem-properties When the script is run the array displays but col 0 is blank for all rows. Link to comment Share on other sites More sharing options...
hazed Posted April 25, 2012 Share Posted April 25, 2012 I think I want to run a script to check all unread mail in this Mailbox, each piece of mail has a web link in it that I need to open and print, then I want to take the subject of the mail and add a status like "-Printed 2/24/2012" to the end of subject. then mark it read. Link to comment Share on other sites More sharing options...
water Posted April 25, 2012 Author Share Posted April 25, 2012 hazed, Example #4 in _OL_ItemFind shows how to search for unread items. Specify Body or HTMLBody to get the body of the mail. The returned data may be cut off. If this is the case then please use _OL_Itemget to access the properties. To modify subject and read status please use _OL_ItemModify. 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 More sharing options...
hazed Posted April 25, 2012 Share Posted April 25, 2012 Thank you, maybe my question is if my default mailbox is hazed@xxxx.com, but I also monitor Orders@xxxx.com as a second mailbox, what is the folder in _OL_itemfindThis is where My issue is, what I was getting when I ran test were just data from hazed@XXXX.com, i believe. Link to comment Share on other sites More sharing options...
water Posted April 25, 2012 Author Share Posted April 25, 2012 Use _OL_FolderAccess to access another mailbox. 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 More sharing options...
hazed Posted April 25, 2012 Share Posted April 25, 2012 Got it, Thank you, I had to figure out the what name of folder I wanted to access. All the examples had "*Outlook-UDF-TestTargetFolder.." So I was tryng to mimic it by doing "*Orders" when I only needed to do "Orders" Thank you, Now the fun begins Link to comment Share on other sites More sharing options...
water Posted April 25, 2012 Author Share Posted April 25, 2012 Ok so i've changed my code to $sFilter = "@SQL=(""urn:schemas:httpmail:hasattachment"" = 1)" $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $sFilter, "http://schemas.microsoft.com/mapi/proptag/0x3707001E") to get PR_ATTACH_LONG_FILENAME as per http://stackoverflow.com/questions/46576...cely-reading-outlook-mailitem- When the script is run the array displays but col 0 is blank for all rows. With this property you can only search a mail item but not a folder - at least that#s how I understand it and what the error messages I get tell me. Looks like you need to stick with what I suggested before. 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 More sharing options...
water Posted April 25, 2012 Author Share Posted April 25, 2012 Got it, Thank you, I had to figure out the what name of folder I wanted to access. All the examples had "*Outlook-UDF-TestTargetFolder.." So I was tryng to mimic it by doing "*Orders" when I only needed to do "Orders"Thank you, Now the fun begins And I'm sure some questions will arise too 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 More sharing options...
Recommended Posts