Solved Outlook MailItem.To Not displaying full email address

FAB1

Registered User.
Local time
Today, 20:24
Joined
Jul 27, 2007
Messages
40
Re:Outlook2016

Hi All, In my last post I ended up with code that has been the base for my email import routine. https://www.access-programmers.co.u...a-cant-figure-out-what-im-doing-wrong.313848/
When I started on phase 2 I have now realized that the outlooks MailItem.To property doesn’t always give the actual full email address like the MailItem.SenderEmailAddress property does

I cant seem to find any uptodate working solutions. Anybody have any ideas?
 
So inspect the Outlook email object and see what has a full email address.?
I seem to recall a lot of what appeared to be duplicates, but must be that way for some reason?
 
The To property of the MailItem object contains the display names only, not the full email address:
You should use the Recipients collection (in your importing routine) to gather the email addresses instead of relying on To, CC and Bcc.

Cheers,
 
@FAB1 just to add on to what bastanu said, with the Recipients collection, you can get a single Recipient. One of its properties is Address. Hopefully, where you are working, this results in an email address. For me, it resulted in a string like this:

/o=ExchangeLabs/ou=Exchange Administrative Group (@@@@@@@)/cn=Recipients/cn=6276fb5161114dc3a7fc1652a24808c4-Username

...where the @'s were random looking alpha characters and "Username" was my actual network login id (I just redacted here for privacy).

If this is your case, you might be able to take the Username at the end, and use it to query LDAP for the email address. Let me know if you end up in this particular status and need any more help.
 
The To property of the MailItem object contains the display names only, not the full email address:
You should use the Recipients collection (in your importing routine) to gather the email addresses instead of relying on To, CC and Bcc.

Cheers,
Hi @bastanu thank you for replying i had looked at https://docs.microsoft.com/en-us/office/vba/api/outlook.recipients and tried Msg.Recipients but the results where blank i had also tried Msg.Recipients.item(1) but again some times it was full address sum times Screen name. When i looked at the .Recipients Methods and other Properties Add, Count, Class etc they didn't seem applicable to me. Do you have an example of how to " gather the email addresses instead of relying on To, CC and Bcc."
 
@FAB1 just to add on to what bastanu said, with the Recipients collection, you can get a single Recipient. One of its properties is Address. Hopefully, where you are working, this results in an email address. For me, it resulted in a string like this:

/o=ExchangeLabs/ou=Exchange Administrative Group (@@@@@@@)/cn=Recipients/cn=6276fb5161114dc3a7fc1652a24808c4-Username

...where the @'s were random looking alpha characters and "Username" was my actual network login id (I just redacted here for privacy).

If this is your case, you might be able to take the Username at the end, and use it to query LDAP for the email address. Let me know if you end up in this particular status and need any more help.
Hi @Isaac thankyou for replying. We don`t us Exchange server just Pop accounts. I cant see .Address in the .Recipients collection. I did try it Msg.Recipients.Address but it returned blank results. Any other ideas?
 
Hi @Isaac thankyou for replying. We don`t us Exchange server just Pop accounts. I cant see .Address in the .Recipients collection. I did try it Msg.Recipients.Address but it returned blank results. Any other ideas?
Recipients is a collection, Recipient is a single object inside the collection. The property belongs to Recipient.
As Gasman has alluded to. So you could:

Code:
dim Recs as outlook.Recipients, Rec as outlook.Recipient
set Recs=mailitem.recipients
for each rec in recs
   rec.address ..........
next rec
 
Here is some code that might help you
Code:
Sub GetSMTPAddressForRecipients(mail As Outlook.MailItem)
    Dim recips As Outlook.Recipients
    Dim recip As Outlook.Recipient
    Dim pa As Outlook.PropertyAccessor
    Const PR_SMTP_ADDRESS As String = _
        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    Set recips = mail.Recipients
    For Each recip In recips
        Set pa = recip.PropertyAccessor
        Debug.Print recip.name &; " SMTP=" _
           &; pa.GetProperty(PR_SMTP_ADDRESS)
    Next
End Sub
Source:

Cheers,
Vlad
 
Here is some code that might help you
Code:
Sub GetSMTPAddressForRecipients(mail As Outlook.MailItem)
    Dim recips As Outlook.Recipients
    Dim recip As Outlook.Recipient
    Dim pa As Outlook.PropertyAccessor
    Const PR_SMTP_ADDRESS As String = _
        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
    Set recips = mail.Recipients
    For Each recip In recips
        Set pa = recip.PropertyAccessor
        Debug.Print recip.name &; " SMTP=" _
           &; pa.GetProperty(PR_SMTP_ADDRESS)
    Next
End Sub
Source:

Cheers,
Vlad
i believe the scheme is no longer working
 

Users who are viewing this thread

Back
Top Bottom