Jump to content

Get current ItemId in Outlook Rules Filter


Exit
 Share

Go to solution Solved by Exit,

Recommended Posts

I want to call an Autoit exe in a filter rule of Outlook.

The following script is called on every new email in my inbox.

But there is a problem: I don't know how to identify the current mail id.

#include <OutlookEX.au3>
$oOL = _OL_Open()

$CurentMailItem = $oOL.current.Id ; <<===== How to determine current Mail Item ???

$subject = $CurentMailItem.subject
$rc = _OL_Close($oOL)
MsgBox(0, "Current Mail Item ", "Subject is: " & $subject, 100)

Can someone point me in the right direction ?

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

I too haven't found a way to retrieve the Id when calling an Exe by a rule.

But you can process every new mail by using events.

Example script _OL_Example_NewMail_Event.au3 shows how it works.

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

  • Solution

I solved the problem by using a script to call my EXE with the entryid as parameter.  

At first, create a VBA script by using Alt-F11 in Outlook:

Sub OutlookFilter(Item As Outlook.MailItem)
    x = Shell(Environ("USERPROFILE") & "\Data\Autoit\OutlookFilter.exe " & Item.EntryID, vbHide)
End Sub
Define a Outlook rule to call the script.

 

Create the EXE. Here a sample.

#include <OutlookEX.au3>
#include <Array.au3>
$oOL = _OL_Open()
$EntryId = $cmdlineraw
$Item = _OL_ItemGet($oOL, $EntryId)
;_ArrayDisplay($item) ; uncomment for debugging
$Body = $Item[9][1]
$SentOn = $Item[70][1]
$SenderEmailAddress = $Item[64][1]
$Subject = $Item[74][1]
;Beep(1000, 100) ; uncomment for debugging
Select
    Case $Body = ""   ; empty body is probable spam
        $rc = _OL_ItemMove($oOL, $EntryId, Default, "Persönliche Ordner\Junk-E-Mail\NoBody")
    Case $SentOn = "45010101000000"   ; no sent date is probable spam
        ;$rc = _OL_ItemDelete($oOL, $EntryId)  ; change MOVE to DELETE if you want no check
        $rc = _OL_ItemMove($oOL, $EntryId, Default, "Persönliche Ordner\Junk-E-Mail\NoSent")
    Case StringRegExp($Subject, "*** GMX Spamverdacht ***")  ; Classified as spam by GMX
        $rc = _OL_ItemMove($oOL, $EntryId, Default, "Persönliche Ordner\Junk-E-Mail\*** GMX Spamverdacht ***")
    Case StringRegExp($SenderEmailAddress, "@firstentry@" & _
            "|news@aldi-sued.de" & _
            "|@anywhere.com" & _
            "|@lastentry@")    ; put advertisung in a separate folder
        $rc = _OL_ItemMove($oOL, $EntryId, Default, "Persönliche Ordner\Posteingang\Werbung")
EndSelect
_OL_Close($oOL)
Don't forget to create the destination folders :graduated:

 

Hope, this helps others to code Outlook rules in Autoit.

Edited by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Thanks for sharing :)

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...