Jump to content

Read Email with Outlook UDF


Recommended Posts

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

 

 

 

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

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

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

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

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

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)

 

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

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 ?

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

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)

 

Link to comment
Share on other sites

Great :)

 

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

  • 1 year later...

I have written an au3 file to read outlook messages using this UDF.
The script will be running in the background waiting for emails.

So far it is working fine.

But if I launch the script(compiled exe) using startup folder in localappdata or run registry in both HKLM or HKCU.

The exe is launching but not detecting the outlook process to interact with as it is not detecting any mails.

Once I quit that and relaunch again manually by double clicking the exe, it is interacting.

 

Any suggestion how to set it to autolaunch to work with outlook.

Link to comment
Share on other sites

Seems the cause of this problem is described in the wiki: https://www.autoitscript.com/wiki/OutlookEX_UDF_-_General#Debugging

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

Thanks @water

In your link, it is mentioned that both Outlook and udf should access with the same user/rights.

I have kept the udf exe in the startup folder of current user and even checked that whether it is running with same user or not from task manager.But still the issue persists.

It is working if I launch directly but not with startup.Any other alternative to run this automatically when we login to machine?

I tried below but not working.

Hklm\run and hkcu\run and current user and all user startup.

Link to comment
Share on other sites

What's the value of @error and @extended of _OL_Open when running from your startup folder?

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

Could you please post your script so I can play with it?

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