franpol38000

Read Email with Outlook UDF

14 posts in this topic

Hello, i'm a french beginner to the software Autoit. The french autoit forum is useful but a little bit light for the reading mail. 

So, I'd like to get email that i recieve on my Outlook mail and which is in status unread. I want to be able to get the content of these emails to analyse it.

For this moment i try this code without success because i get error 3

#include <Outlook.au3>

$oOutlook = _OutlookOpen()
        $sFolder = $olFolderInbox ;(if i exhange with the .pst file of outlook i get error 5 (Mailfolder not found))
        $Non_lu = _OutlookGetMail($oOutlook, $sFolder, True, "", "", "", "", "", "", True, "", 0)
        Global $Tableau[100][2]

        If Not @error Then
            For $i = 1 To $Non_lu[0][1]
                ConsoleWrite($i & " / " & $Non_lu[0][1])
                $Tableau[$i][0] = $Non_lu[$i][0]
                $Tableau[$i][1] = $Non_lu[$i][1]
            Next
            _ArrayDisplay($Tableau)
        Else
            MsgBox(0, "Erreur", "Code erreur : " & @error)
        EndIf

 

Is it possible  to read e-mails with OutlookEx.au3 UDF ? Maybe because of my English level I didn't find the answer on the site.

Could someone help me to  find the answer?

Thanks in advance

 

 

 

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Sure you can use the OutkookEx UDF to retrieve the unread mails. 😊

Please check the example scripts for _OL_ItemFind. 


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
49 minutes ago, water said:

Welcome to AutoIt and the forum!

Sure you can use the OutkookEx UDF to retrieve the unread mails. 😊

Please check the example scripts for _OL_ItemFind. 

Thank you  Water for your fast answer thanks to I learnt something interesting.

I tried the example scripts _OL_ItemFind and unfortunately i got error 501 with extended 400 for the environment test.

I saw this error was in relation with the Outlook "Appointment", then I tried the script without this test and i got an array with the following elements visible in the attached picture (in my email box, I've more than 150 unread emails, so there is a problem) .

I tried to change the folder with the function  _OL_FolderAccess() , but in this case i got the message "could not find an unread mail, ...". With my level, I don't know what I can do now.

#Include <Array.au3>
#include <OutlookEX.au3>

$oOutlook = _OL_Open()
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
        $Result = _OL_TestEnvironmentCreate($oOutlook)
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)
        $Folder =_OL_FolderAccess($oOutlook, "C:\Users\FRANP\AppData\Local\Microsoft\Outlook\Outlblabla@outlook.com-00000009.pst")
        ;$aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, "[UnRead]=True", "", "", "Subject,Body", "", 1)
        $aItems = _OL_ItemFind($oOutlook, $Folder, $olMail, "[UnRead]=True", "", "", "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)

Have you some idea how to read my unread e-mails ?

Thanks in advance

 

 

array outlook.jpg

Share this post


Link to post
Share on other sites

I'm on vacation right now but will provide a working example quite soon. 


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

#5 ·  Posted (edited)

Thanks water, I wish you a nice holidays :)

 

I add some informations which can be maybe usefull :

OS : Windows 10 family

Autoit : AutoIt Version : 3.3.14.2

Outlook: Outlook 2007

UDF OutlookEx :  1.2.1.0

 

Edited by franpol38000
additionnal information

Share this post


Link to post
Share on other sites

This should work (modify _OL_FolderAccess):

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

$oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
; $aFolder = _OL_FolderAccess($oOutlook, "C:\Users\FRANP\AppData\Local\Microsoft\Outlook\Outlblabla@outlook.com-00000009.pst")
$aFolder = _OL_FolderAccess($oOutlook, "", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing PST. @error = " & @error & ", @extended = " & @extended)
$aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[UnRead]=True", "", "", "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)

 


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

Thank you Water for your help,

Unfortunately, I've still the same problem with your code, the array is empty like the picture I sent above.

It's like I've no connection with Outlook2007 and the UDF ! What can I do ?

 


 

 

Share this post


Link to post
Share on other sites

To access a PST file so that Outlook can see it as a folder you need to use _OL_PSTAccess.
Then you need to use _OL_FolderAccess so that the OutlookEX UDF can process the items.


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

Great, Finally I get the emails in the array :-)

But, I need to learn more to get exactly what I really want.

First, I would like see only the unread emails in my inbox (not the unread emails deleted ) and after I would like know the email adress from the sender.

I tried to find some examples for it but I didn't arrive.

My wish will be something like this :

$aItems = _OL_ItemFind($oOutlook, $oPST, $olMail, "[UnRead]=True" And  [Inbox]=True , "", "", "From,Subject,Body", "", 1)

Is it possible to get this information ?

If yes, Could you please give me an idea to do it ?

Thanks a lot for your help.

 

Below the actual code which could maybe help someone else

$oOutlook = _OL_Open()
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

        $oPST = _OL_PSTAccess($oOutlook, "C:\Users\FRANP\AppData\Local\Microsoft\Outlook\Outlblabla@outlook.com-00000009.pst", "Outlook-UDF-PST")
        If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_PSTAccess Example Script", "Error accessing archive. @error = " & @error & ", @extended: " & @extended)
        MsgBox(64, "OutlookEX UDF: _OL_PSTAccess Example Script", "Archive successfully accessed!")
        
        $aItems = _OL_ItemFind($oOutlook, $oPST, $olMail, "[UnRead]=True", "", "", "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)

 

Share this post


Link to post
Share on other sites

You need something like this.
Note that after _OL_PSTAccess I added _OL_FolderAccess to work with the INBOX of the PST.

#include <Array.au3>
#include <OutlookEX.au3>
$oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

$oPST = _OL_PSTAccess($oOutlook, "C:\Users\FRANP\AppData\Local\Microsoft\Outlook\Outlblabla@outlook.com-00000009.pst", "Outlook-UDF-PST")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_PSTAccess Example Script", "Error accessing archive PST. @error = " & @error & ", @extended: " & @extended)
MsgBox(64, "OutlookEX UDF: _OL_PSTAccess Example Script", "Archive successfully accessed!")

$aFolder = _OL_FolderAccess($oOutlook, "Outlook-UDF-PST", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_PSTAccess Example Script", "Error accessing archive folder. @error = " & @error & ", @extended: " & @extended)
$aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[UnRead]=True", "", "", "EntryID,Subject,SenderEmailAddress", "", 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)

Property "SenderEmailAddress" will only return an SMTP address for external users. For Exchange users you would need to resolve the recipient.


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

Thanks water, your code is perfect,

I could include each email with the details i would (adress, subject, ...) in the excel file with the UDF "Excel.au3".

To finish this exercice, Could you please tell me if there is a function to change the status of the email in Outlook (Unread to read) with the "EntryID" information or other? If yes, what is the name of this function ?

Share this post


Link to post
Share on other sites

Sure there is. Try function _OL_ItemModify and set property "Unread" to "True".


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

Thanks,

to help someone else below the syntaxe of this function

$oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
$aFolder = _OL_FolderAccess($oOutlook, "Outlook-UDF-PST", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_PSTAccess Example Script", "Error accessing archive folder. @error = " & @error & ", @extended: " & @extended)
$aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "[UnRead]=True", "", "", "EntryID,Subject,Body,SenderEmailAddress", "", 1)
$iRows = (UBound($aItems, $UBOUND_ROWS))-1 ;i count the line of this array

For $i=1 To $iRows Step 1
    _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Unread=False");passé le mail en read
Next

_OL_Close($oOutlook)

 

Share this post


Link to post
Share on other sites

Great :)

 


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