none
Retrieve SMTP address from sender RRS feed

  • Question

  • I'm at my wits end!
    I've seen a few examples to achieve this, but none work in my loop - could it be because I'm instantiating another Outlook object when one exists?
    Code - which just hangs:
    Sub GetAddressFromCDO()
        Dim olApp As Outlook.Application
       Dim objSession As MAPI.Session
       Dim objInboxMsgs As MAPI.Messages
       Dim objMsg As MAPI.Message
       Dim strAddress As String
       Const g_PR_SMTP_ADDRESS_W = &H39FE001F
       Set olApp = CreateObject("outlook.application")
       Set objSession = CreateObject("MAPI.Session")
       objSession.Logon NewSession:=False
       Set objInboxMsgs = objSession.Inbox.Messages
       
       For Each objMsg In objInboxMsgs
          Debug.Print objMsg.Subject
          objMsg.SenderEmailAddress
          ' If the e-mail sender is an Exchange user, the e-mail address
          ' will return as an X400 address and not an SMTP address.
          ' If the Address property does not return a fully qualified
          ' address (for example, containing an @), try the &H39FE001F MAPI
          ' IMPORTANT: This property is not documented on MSDN.
          If Not InStr(strAddress, "@") Then
             On Error Resume Next
             strAddress = objMsg.sender.Fields(g_PR_SMTP_ADDRESS_W).Value
          End If
          Debug.Print strAddress
          Debug.Print
       Next
          
       objSession.Logoff
       Set objMsg = Nothing
       Set objInboxMsgs = Nothing
       Set objSession = Nothing
    End Sub
    • Moved by Fiona_LiaoModerator Thursday, August 4, 2011 1:56 AM script related request (From:Clients)
    Friday, July 22, 2011 9:24 AM

All replies