mjolnirmarkiv Posted January 22, 2014 Share Posted January 22, 2014 Hello there, I have stumbled upon a little problem, I hope you might help me with. I'm creating a bunch of mail items in Outlook in my script (btw thanks to water and wooltown for OulookEx UDF, saved me a lot of time). Function that does that returns $mail_items array on success, which contains created mail item objects. After I dsiplay those mail items the idea is to track Close event of those items or inspector object associated with items in the main loop: If IsArray ($mail_items) Then For $i = 0 To UBound ($mail_items) - 1 ;Check if mail item is closed and do whatever Next EndIf I've looked at MSDN, but I'm not sure how to incoporate that in AutoIt code, the best I was able to do is to close opened mail items programmatically) but that's not I was trying to do, I need Close as event, not method. Link to comment Share on other sites More sharing options...
Solution water Posted January 22, 2014 Solution Share Posted January 22, 2014 The example scripts section provides an example to handle events. Check the two examples >here. Here you find the events for Mailitems. Here the events for Inspectors. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 22, 2014 Author Share Posted January 22, 2014 Thank you again, water, it worked! BTW is there any easy way to retrieve closed item object within _Close function? I didn't find better solution but to loop through opened Inspectors and compare Inspector.CurrentItem to array of $mail_items to see if the item is still opened and if not do whatever with it. Link to comment Share on other sites More sharing options...
water Posted January 22, 2014 Share Posted January 22, 2014 Another idea I've found on the web is to check the write event for the mail item. Occurres when the user closes the inspector and saves the changes. MSDN. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 22, 2014 Share Posted January 22, 2014 Another good read is this MSDN page: "How to: Implement a Wrapper for Inspectors and Track Item-Level Events in Each Inspector" My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 22, 2014 Author Share Posted January 22, 2014 (edited) Funny thing is if I change opened mail item (even if I won't save it), the method of looping through opened inspectors doesn't work. Might need to figure smth else out. Edited January 22, 2014 by mjolnirmarkiv Link to comment Share on other sites More sharing options...
water Posted January 22, 2014 Share Posted January 22, 2014 What I understand from your OP you create multiple mail items, display them and then need to further process them when the user closes the inspector? Couldn't you process one mail after the other? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 23, 2014 Author Share Posted January 23, 2014 (edited) Yes, more or less. Depending on the user choice it either sends created mail items or displays them, so the user could do whatever with them (usually review, review and update and send), but if the latter weren't sent I want them to be deleted. But I'm really nitpicking here so nevermind) as script is functional as it is. Just do not want Drafts folder to be flooded with "unused" mail items, so I was hoping to track created mails down and delete them on inspector close. Not sure why it doesn't work if I change item, does it makes Inspectors.item(x).CurrentItem object somehow different than it used to be? Edited January 23, 2014 by mjolnirmarkiv Link to comment Share on other sites More sharing options...
water Posted January 23, 2014 Share Posted January 23, 2014 I haven't played too much with events, so I can't tell waht's going on in this case. Maybe you could separate the tasks. I would write the EntryID of every created mail item to a file. When your script is started up the next time, call a cleanup function. This function reads the file, scans the draft folder for every entry and then (optionally) asks the user if the drafts should be deleted. All deleted EntryIDs are then removed from the file. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 23, 2014 Author Share Posted January 23, 2014 Well, the answer to my question what's going on in this case turned out to be pretty obvious. I'm closing the item > item close event fired > prompt appear "Wanna save your changes, yes or no?" > item close event won't wait for me - func exit > nothing was deleted. So I intercept .GetInspector.Close now, it works just like it supposed to. Link to comment Share on other sites More sharing options...
water Posted January 23, 2014 Share Posted January 23, 2014 Sounds good! Thanks for the reply. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 24, 2014 Author Share Posted January 24, 2014 I continue playing with events in Outlook, but could not get this to work. It intercepts the event, but won't return the object of the sent item (I assume it should?). Does anyone have an idea why? #include <OutlookEX.au3> $outlook = ObjCreate ("Outlook.Application") ObjEvent ($outlook, "Outlook") While 1 Sleep (10) WEnd ;http://msdn.microsoft.com/en-us/library/office/bb147641(v=office.12).aspx Func OutlookItemSend ($sent_item) MsgBox (0, "", "The following item has been sent: """ & $sent_item.Subject & """") EndFunc Link to comment Share on other sites More sharing options...
water Posted January 24, 2014 Share Posted January 24, 2014 Iirc the Outlook examples thread contains an example My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted January 25, 2014 Author Share Posted January 25, 2014 They are, and that's the puzzlign thing. They retreive everything successfully like they should, but not in case of Application.ItemSend event (I've tried different names, different number of parameters -- there're 2 of them actually -- nothing). But again that's more of curiosity thing for me since Inspector.Close event still happeing and it's doing everything I want, so feel free to not bother) Thanks again for all the help. Link to comment Share on other sites More sharing options...
water Posted January 25, 2014 Share Posted January 25, 2014 The examle script isn't triggered by the ItemSend event but by ItemAdd. When a mail has been sent a copy is added to the "Sent Mails" folder and event ItemAdd is triggered for this folder. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now