Sign in to follow this  
Followers 0
mjolnirmarkiv

Intercepting Close event in Outlook

15 posts in this topic

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.

 

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by mjolnirmarkiv

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by mjolnirmarkiv

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Sounds good! Thanks for the reply.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Iirc the Outlook examples thread contains an example


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0