Jump to content

Outlook: Get list of unread mails in all folders and process when mail gets read


Recommended Posts

Hi Storme,

I moved the discussion from PM to a thread because I now start to post code and this might be useful for other users.

Part one:

Get list of folders with unread mails:

Part One.au3

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Part two:

Get all unread mails from all folders and return their EntryIDs in an array:

Part Two.au3

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Are now that makes more sense.

When you siad you could check for "unread" emails I thought it was some function in the UDF.

NOW I see there are properties...HMMM

I'm going to have to have a good read through your UDF to see what else I'm missing out on :)

Thank you!

John Morrison

Link to comment
Share on other sites

Right now I try to catch the event when a mail gets read. It works - kind of - but unfortunately I can't get rid of an event I have already processed and therefore the longer the script runs the more events are fired even when the user only changed one mail. Needs more investigation ...

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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 Storme,

it took some time and some head scratching but now I have a solution to grab the event as soon as the "Unread" property of a mail item changes.

This example script writes the subject, the property and the properties value of every changed mail item to the console.

At the moment it works for items you right click in the Explorer and set to read or unread. How to grab the event when you open the item is under investigation.

Use Shift-Alt-E to exit the script.

Does this work for you?

_OL_Example_ReadMail2_Event.au3

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Sorry Water it crashes on my system. Outlook 2007, on Windows XP 32bit

_OL_Example_ReadMail2_Event.au3 (20) : ==> The requested action with this object has failed.:
If $oExplorer.Selection.Location = $olViewList Then
If $oExplorer.Selection.Location ^ ERROR

This happens if I just change focus to a new item.

If I right click and make the focused item read then I get this.

Updates in Your Groups, July 21, 2012 UnRead changed to True
_OL_Example_ReadMail2_Event.au3 (20) : ==> The requested action with this object has failed.:
If $oExplorer.Selection.Location = $olViewList Then
If $oExplorer.Selection.Location ^ ERROR

So a partial success!

:(

Link to comment
Share on other sites

This property isn't available with OL 2007. Can you just drop the IF statement?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Yep that worked!

I didn't want to remove it incase it was important to the code.

One more puzzle for you..

If I mark an UNREAD emal READ I get

Updates in Your Groups, July 21, 2012 UnRead changed to True

It looks like the property is being read "before" the change.

The code can be a bit deciving as well.

ConsoleWrite($oSelected.Subject & " " & $sProperty & " changed to " & $oSelected.Unread & @CRLF)

You are using $sProperty for the name of the property but $oSelected.Unread for the property state.

DAM just found a problem with the code....

If I right click a non focused item and change it's read status the script doesn't recognise that any change was made. :(

Link to comment
Share on other sites

If I mark an UNREAD emal READ I get

Updates in Your Groups, July 21, 2012 UnRead changed to True

It looks like the property is being read "before" the change.

Haven't noticed this with Outlook 2010 when testing - will re-check and come back.

You are using $sProperty for the name of the property but $oSelected.Unread for the property state.

$sProperty contains the name of the changed property. Depending on the content of this variable the code will do the required processing.

I will change the example to make it more obvious.

If I right click a non focused item and change it's read status the script doesn't recognise that any change was made. :(

Not sure if this is handled by the ChangeSelection event but will check.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

DAM just found a problem with the code....

If I right click a non focused item and change it's read status the script doesn't recognise that any change was made. :(

Seems this situation isn't handled by a selection. Based on this site:

"When you right-click an email in Outlook 2000 – 2002, the right-clicked item gets selected .... This produces ExplorerSelectionchange ...

In Outlook 2003, right-clicking an item doesn’t select it.

In Outlook 2007 and 2010, right-clicking an item doesn’t select it either."

Looks as if we are out of luck with our approach of getting all read mails by handling the corresponding events. Can you live with this shortcoming or do you need a 100% user-proof solution?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

:( in this case it's got to be 100% user proof as the users arn't computer .....smart.....

No real problem I'll get back to the original idea using the code you gave me above and just do compares every N minutes.

It would have made things a lot simplier but I've already made up most of the code in my head for the original approach so I just have to get it out of there and into the computer. :)

A very big thanks for you effort and a GREAT UDF!!! Without it I wouldn't have even tried this.

John Morrison

Edited by storme
Link to comment
Share on other sites

OK, to make it 100% user proof I would use the following approach:

  • Let your script start Outlook and put the script in the AutoStart folder - this way you can be sure that the user hasn't processed mails before the script starts up
  • Do a check at startup time. If Outlook is already running then the user managed to bypass your script. Send a MsgBox to inform the user that he can't be sure the script grabs all the mails he processed while the script was not running
  • After startup process all unread mails by searching the folders and store them in an array (EntryId). This way you get all mails that arrived while the computer was off or the script was not running.
  • After the initial processing wait for the new mail event (for an example please check the Example Scripts thread) and add this mails to the array. This enhances performance
  • Every n minutes check the read status of all mails in the array using _OL_ItemGet and specifiying the property "UnRead"
  • For all read items store the info required to identify the mail on the other machine on the shared drive
Just my 0.02 $.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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
 Share

  • Recently Browsing   0 members

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