Jump to content

how to get email address of sender in outlook


 Share

Recommended Posts

Hi Everyone / MVPs / Experts :)

 

I have an issue on retrieving an email address of a sender in outlook using below code.

it only get the AD properties like below rather than Email Address

example:

 /O=COMCAST/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=RFITZG203FAE

Below is my code: based on OutlookEX.au3

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

Global $aOL_Item = _OL_ItemFind($oOutlook, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation", $olMail, "[UnRead]=True", "", "", "EntryID,body,receivedtime,senderemailaddress", "", 2)
;_ArrayDisplay($aOL_Item)

$emailadd = _ArrayToString($aOL_Item,"",1,1,"",3,3) ; body
ConsoleWrite($emailadd)

Your help will be greatly appreciated.

Link to comment
Share on other sites

Something like this (untested):

Local $oOL_Item = $oOutlook.Session.GetItemFromID($aOL_Item[1][1], Default)
    Local $oOL_Sender = $oOL_Item.Sender
    If $oOL_Sender.AddressEntryUserType = $olExchangeUserAddressEntry Or $oOL_Sender.AddressEntryUserType = $olExchangeRemoteUserAddressEntry Then
        Local $oExchangeUser = $oOL_Sender.GetExchangeUser
        MsgBox(0, "Mail", $oExchangeUser.PrimarySmtpAddress)
    EndIf

 

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

Hi Water, 

I tried this code but does not show anything.

I tried to put an else statement to check if condition is true and got the "failed" result.

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

Global $aOL_Item = _OL_ItemFind($oOutlook, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation", $olMail, "[UnRead]=True", "", "", "EntryID,body,receivedtime,senderemailaddress", "", 2)
;_ArrayDisplay($aOL_Item)

Local $oOL_Item = $oOutlook.Session.GetItemFromID($aOL_Item[1][1], Default)
    Local $oOL_Sender = $oOL_Item.Sender
    If $oOL_Sender.AddressEntryUserType = $olExchangeUserAddressEntry Or $oOL_Sender.AddressEntryUserType = $olExchangeRemoteUserAddressEntry Then
        Local $oExchangeUser = $oOL_Sender.GetExchangeUser
        MsgBox(0, "Mail", $oExchangeUser.PrimarySmtpAddress)
    Else
        MsgBox(0,"Mail","Failed") ; Added this to check if condition is met or not.
    EndIf

 

Link to comment
Share on other sites

Does _Arraydisplay (now commented) display EntryId in row 1?

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

Hi Water,

 

Sorry for the confusion. I commented _arraydisplay() just to push through the output at once.

the result of arraydisplay where "SenderEmailAddress" output shows is in row 1, column 3.

it shows like below and not as an email address.

/O=COMCAST/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=RFITZG203FAE

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

Global $aOL_Item = _OL_ItemFind($oOutlook, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation", $olMail, "[UnRead]=True", "", "", "EntryID,body,receivedtime,senderemailaddress", "", 2)
_ArrayDisplay($aOL_Item)

Local $oOL_Item = $oOutlook.Session.GetItemFromID($aOL_Item[1][3], Default)
    Local $oOL_Sender = $oOL_Item.Sender
    If $oOL_Sender.AddressEntryUserType = $olExchangeUserAddressEntry Or $oOL_Sender.AddressEntryUserType = $olExchangeRemoteUserAddressEntry Then
        Local $oExchangeUser = $oOL_Sender.GetExchangeUser
        MsgBox(0, "Mail", $oExchangeUser.PrimarySmtpAddress)
    Else 
        MsgBox(0,"Mail","Failed")
    EndIf

 

Link to comment
Share on other sites

We need the EntryID to retrieve the senders mail address. So you need to use

$aOL_Item[1][0]

right?

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

:)

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