Consulting

Results 1 to 3 of 3

Thread: Fetch senders email-adress

  1. #1
    VBAX Regular
    Joined
    Mar 2016
    Location
    Oslo
    Posts
    17
    Location

    Fetch senders email-adress

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

    Any hints or tips would be greatly appreciated

    kode.JPG
    Last edited by vegard_fv; 02-07-2019 at 03:58 AM.

  2. #2
    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
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Mar 2016
    Location
    Oslo
    Posts
    17
    Location
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •