Counting Mails in Outlook with Autohotkey

682 Views Asked by At

I tried to write a script, that counts the e-Mails in a specific public exchange folder in outlook. If there are Mails in subfolder2, a Messagebox should open and tell me, how many Mails there are. I tried this, but it did not work.

    Outlook := ComObjActive("Outlook.Application")
    mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")
    if (mail.Items.Count>0)
    {
    msgbox % mail.Items.Count "Mails in folder"
    }
    else
    {
    msgbox No Mails.
    }

Does anyone has a idea, how I should change the script, that it works?

3

There are 3 best solutions below

0
On BEST ANSWER

I got it. I simply removed the Variable.

 Outlook := ComObjActive("Outlook.Application")
    if (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count>0)
    {
    msgbox % Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count "Mails in folder"
    }
    else
    {
    msgbox No Mails.
    }

Thanks for the help :D

1
On

Please try to use this:

mail := Outlook.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")

4
On

You must retrieve subfoldersone at a time, you cannot specify a path. Change the line

 mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")

to

 mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2")