I am trying to get all the email addresses in "TO" section of received mails. This code is giving a link ( like below) for each mail. I am not sure how to fetch the email address and NOT A LINK OR THE DISPLAY NAME FOR THE EMAIL.
Any help is highly appreciated !
It's giving a link like below instead of Email address in "TO" -
"/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=636da3beeae34f2493a3ee2c93d44007-LC",
where LC is the display name of the account mail is received from.
Sub openLeaseInbox()
Dim oOutlook As Outlook.Application
Dim oFolder As Outlook.Folder
Dim oMailBox As String
Dim oFldr As String
Dim XDate As Date
Dim i As Integer
Dim olMail As Outlook.MailItem
Dim olrecips As Outlook.Recipients
Dim olrecip As Outlook.Recipient
Dim LR As Integer
Range("L2").Value = "3/20/2022"
XDate = Format(ThisWorkbook.Sheets("Email Download").Range("L2").Value, "mm/dd/yyyy")
Set oOutlook = CreateObject("Outlook.Application")
Set oNS = oOutlook.GetNamespace("MAPI")
oMailBox = "Lease QC"oFldr = "Inbox"
Set oFolder = oNS.Folders(oMailBox).Folders(oFldr)
If (oOutlook.ActiveExplorer Is Nothing) Then
oFolder.Display
Else
Set oOutlook.ActiveExplorer = oFolder
End If
i = 1
For Each olMail In oFolder.Items.Restrict("[ReceivedTime] < '" & XDate & "' ")
Set olrecips = olMail.Recipients
Range("A1").Offset(i, 0).Value = olMail.Subject
Range("B1").Offset(i, 0).Value = olMail.ReceivedTime
For Each olrecip In olrecips
Range("C1").Offset(i, 0).Value = olrecip.Address ' Seems there is a problem here'
Next
Range("D1").Offset(i, 0).Value = olMail.body
i = i + 1
Next olMail
End Sub