Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted (edited)

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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

  • Moderators
Posted

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

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
  • Moderators
Posted

Yes, you can do a for loop to loop through the array, and do something like:

If StringInStr($aItems[$i][1], "My Search Term") Then
   ;Do Stuff
EndIf

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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

  • Moderators
Posted

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)
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
Posted

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 2024-07-28 - Version 1.6.3.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 (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

 

Posted

Hello Water,

 

i tried already this , but failed unfortunately.

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

BR Horphi

Posted (edited)

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 2024-07-28 - Version 1.6.3.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 (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

 

Posted (edited)

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
  • 4 weeks later...
Posted

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 2024-07-28 - Version 1.6.3.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 (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

 

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
  • Recently Browsing   0 members

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