Sign in to follow this  
Followers 0
Exit

Get current ItemId in Outlook Rules Filter

4 posts in this topic

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 ?


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
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 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

#3 ·  Posted (edited)

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

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Thanks for sharing :)

1 person likes this

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