Jump to content
Sign in to follow this  
TheOne23

how to get email address of sender in outlook

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.

Share this post


Link to post
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 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - 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
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


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

 

Share this post


Link to post
Share on other sites

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - 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
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


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

 

Share this post


Link to post
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 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - 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
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi Water,

 

Got your point in there. :)

You solved it as usual. Really appreciated your help.

Thank you so much! 

More Power "Water"

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - 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
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - 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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...