Jump to content
horphi

Outlook Email Content Searchterm possible?

Recommended Posts

horphi

Hello community,

 

nice to be here.

i started with autoit it´s amazing what kind of new world is opening with this awesome tool.

I have a question regarding Outlook.

I want to use AutoIt to look for a string inside the body of the E-Mail.

When you try to get an window ID, the grabber shows unfortunately only the whole outlook window without the Email body...

How i can grab the Text of the E-Mail to search for a specified value, copy them and insert them into another database?

Windows 7 - Outlook 2010

Best regards,

 

Phil

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, horphi, welcome to the forum. This pulls up any mail item in the Inbox with "VDI Project" in the subject. You should be able to modify it easily to search the Body of the email. Take a look at the OutlookEX example for _OL_ItemFind for more info.

#include <OutlookEX.au3>

$oOutlook = _OL_Open()

$aMail = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[Subject]=VDI Project", "", "", "Subject,Body", "", 1)
    If IsArray($aMail) Then _ArrayDisplay($aMail)

 

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
horphi

Hi, horphi, welcome to the forum. This pulls up any mail item in the Inbox with "VDI Project" in the subject. You should be able to modify it easily to search the Body of the email. Take a look at the OutlookEX example for _OL_ItemFind for more info.

#include <OutlookEX.au3>

$oOutlook = _OL_Open()

$aMail = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "[Subject]=VDI Project", "", "", "Subject,Body", "", 1)
    If IsArray($aMail) Then _ArrayDisplay($aMail)

 

Hello JLogan3o13,

thx for the response.

I get the array accomplished but he displays always  zero, although i copied the exact header....

$aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "[Subject]=AW: ACS BEschriftung", "", "", "Subject,Body", "", 1)
If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
EndIf

_OL_Close($oOutlook)

BR

Horphi

Unbenannt.PNG

Share this post


Link to post
Share on other sites
JLogan3o13

You have your folder pointing to *\Posteingang, which would mean it is Mailbox\Posteingang. Is this path correct, or is it a sub-folder of another folder (Inbox, perhaps?). When I create a posteingang folder in the root directory, and add three mail items with the verbiage you have, the array shows just fine:

#include <OutlookEX.au3>

$oOutlook = _OL_Open()
$aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "[Subject]=AW: ACS BEschriftung", "", "", "Subject,Body", "", 1)
If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
EndIf

 

forum.thumb.png.206bd963182f572f52ce8ffb

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
horphi

Hi JLogan3o13,

dont ask me why, i changed nothing (i know that´s not true ;-)) but now it fits....

Same script on another PC with another subject and the result gives the right statment...

Thx for help.

Now the next step is to search in the body for some repeating values, who needs to be copied into another software.

Can i use the array to say in the next loop: use Col1 and get string"_"?

BR

Horphi

 

 

Unbenannt.PNG

Edited by horphi

Share this post


Link to post
Share on other sites
horphi

Hello again,

how can i change the Subject? I want that all E-Mails with the Word "Excel" inside the subject shall be displayed.

 

BR

Horphi

Share this post


Link to post
Share on other sites
JLogan3o13

Well...You've already been shown that this line searches for the term AW: ACS BEschriftung in the subject line:

$aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "[Subject]=AW: ACS BEschriftung", "", "", "Subject,Body", "", 1)

What do you think you would need to change to get it to look for Excel instead?

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
horphi

Hi JLogan3o13,

i want to look for all mails with the subject ACS*....

How can i set the wildcard to look for different subjects?

 

BR Horphi

Share this post


Link to post
Share on other sites
JLogan3o13

horphi, the line in post #8 shows you how to change the subject. What have you tried on your own, and what is not working?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
horphi
HI JLogan3o13,.

what i try is to set  is

"[Subject] = ACS*" 
and not 
"[Subject] = ACS BEschriftung"

Look for all Items with contain the Word ACS in the Subject. Unfortunallety it fails...

 

BR

Edited by horphi

Share this post


Link to post
Share on other sites
water

Parameter $sRestrict does an exact match whereas parameters $sSearchName and $sSearchValue do a partial match. None of them supports wildcards.
So to search for subject with text "ACS" in it try (untested):

#include <OutlookEX.au3>
$oOutlook = _OL_Open()
$aMail = _OL_ItemFind($oOutlook, "*\Inbox", $olMail, "", "Subject", "ACS", "Subject,Body", "", 1)
If IsArray($aMail) Then _ArrayDisplay($aMail)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
horphi

Hello Water,

 

i tried already this , but failed unfortunately.

It means i need always the complete Text of the subject...?

BR Horphi

Share this post


Link to post
Share on other sites
water

Should work because $sSearchName/$sSearchValue uses StringInStr.
Can you please post the code you used?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
horphi

Hello Water,

 

now it works.

I using now the _OL_ItemSearch Function. It needs a while to understand, but it works. :-)

#include <OutlookEX.au3>
#include <Array.au3>
#include <String.au3>
#include <MsgBoxConstants.au3>


Hotkeyset("{F2}", "schliessen")
Func schliessen ()
Exit
EndFunc

Grab_email()

Func Grab_email()
Dim $aItems

Global $oOutlook = _OL_Open()

$StrOutlook_Inbox ="\Inbox"

$strsql = "@SQL=urn:schemas:httpmail:subject like '%SearchTerm%'"

$aItems=_OL_ItemSearch($oOutlook,$StrOutlook_Inbox,$strsql,"Subject,Body")

If IsArray($aItems) Then
    _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script - Unread mails")
Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended)
 EndIf
_FileWriteLog(@ScriptDir & "CDSN.log", "Got the emails Moving to Processing Stage")

EndFunc

BR Horphi

Edited by horphi

Share this post


Link to post
Share on other sites
horphi

Hi WAter,

when you using the ItemSearch, then you get the email body shown in the result?

 

BR

Horphi

Share this post


Link to post
Share on other sites
water

Sorry for the late reply due to vacation etc.
I'm not sure you get the whole body. Maybe just 255 characters. You need to test.
If it is an HTML formatted body then it might help to query property HTMLBody.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

×