
Extracting the Internet Email Address from Inbox Items
Yes, use CDO to get the actual email address. Despite the
documentation, this will work in IMO mode as well as in C/W mode. The
following code will get the email address of the currently open mail
item.
Sub FromAddress()
Dim oNS As Outlook.NameSpace
Dim oItm As Outlook.MailItem
Dim obj As Object
Dim oSession As MAPI.session
Dim oMsg As MAPI.Message
Dim oSndr As MAPI.AddressEntry
Dim sAddress As String
Dim sEntry As String
Set oNS = Application.GetNamespace("MAPI")
Set oItm = Application.ActiveInspector.CurrentItem
'We need the EntryID of the item to locate it with CDO
sEntry = oItm.EntryID
'Establish a CDO (MAPI) Session object and logon to it
Set oSession = CreateObject("MAPI.Session")
oSession.Logon , , False, False
'Locate the current message with the EntryID using CDO
Set oMsg = oSession.GetMessage(sEntry)
'Get the sender's name
Set oSndr = oMsg.Sender
'Get the actual email address
sAddress = oSndr.Address
'Display the information in a MsgBox
MsgBox "Email Address: " _
& sAddress
oSession.Logoff
Set oNS = Nothing
Set oItm = Nothing
Set obj = Nothing
Set oSession = Nothing
Set oMsg = Nothing
Set oSndr = Nothing
End Sub
BTW, please don't cross post to so many groups, pick 1 or 2 of the
most appropriate ones.
--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams
Quote:
> I am writing a custom Email application in an Internet Only Outlook
> configuration. I have several IMAP accounts on which to query from
and I
> was wondering if there is a way to extract the email addresses and
other
> information on incoming Internet messages on multiple IMAP
accounts..
> With Exchange, ususally the email address is resolved with the
Person's Full
> name, and in any other Internet Email application this just won't
do. The
> Object Model for a Mail Item only provides access to the Sender's
name, not
> their email address.
> Any suggestions?
> Thanks In advance.