PDA

View Full Version : Fetch senders email-adress



vegard_fv
02-07-2019, 03:44 AM
Hi guys, I'm trying to fetch the emailadress of a sent email, using the Item object (under ActiveExplorer and Selection). Please see the attached code.

I have tried both .to and .SenderEmailAdress, but I can't get VBA Outlook to return the actual adress. If I manually forward the email, the to-field is listed like this: "To: 'Innsyn Byrådsavdelingene' <innsyn@byr.oslo.kommune.no>". But as you can see, my code is only returning the name, not the email-adress.

It seems like the .to property returns the email-adress with some of my sent emails, but not others. Could it be that it has something to do with my contacts internally in Outlook?

I have searched and searched the object structure both in the locals window in the VBA editor, and the object models on Microsofts page, but I can't figure out what I am doing wrong .... :doh:

Any hints or tips would be greatly appreciated : pray2:

23708

gmayor
02-07-2019, 04:31 AM
Why not use both the sender name and e-mail address e.g.


Sub GetMsg()
Dim olMsg As MailItem
On Error Resume Next
Set olMsg = ActiveExplorer.Selection.Item(1)
MsgBox olMsg.SenderName & " <" & olMsg.SenderEmailAddress & ">"
lbl_Exit:
Set olMsg = Nothing
Exit Sub
End Sub

vegard_fv
02-12-2019, 06:24 AM
I found that the .to - property was returning the email-adress, but as the SMPT-adress.

The beneatch code is returning the adress correctly. But is there any way to do this without prompting Microsofts server each time?


---


Dim OLApp As New Outlook.Application
Dim olExp As Outlook.Explorer
Dim olSel As Outlook.Selection
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor

Set olExp = OLApp.ActiveExplorer
Set olSel = olExp.Selection
Set recips = olSel.Item(1).Recipients

For Each recip In recips
Set pa = recip.PropertyAccessor
Debug.Print pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")
Next recip