Extracting the Internet Email Address from Inbox Items 
Author Message
 Extracting the Internet Email Address from Inbox Items

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.



Sun, 04 Aug 2002 03:00:00 GMT  
 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.



Mon, 05 Aug 2002 03:00:00 GMT  
 Extracting the Internet Email Address from Inbox Items
The Outlook object model doesn't return the EMail address (as you found
out). You'll have to go to CDO (Collaborative Data Objects or some
such). Check out
http://www.slipstick.com/index.htm
and
http://cdolive.com/

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.

--
Bruce H. Johnson
Corporate Knowledge, Inc. Los Angeles, California

#include <std_disclaimer>


Mon, 05 Aug 2002 03:00:00 GMT  
 Extracting the Internet Email Address from Inbox Items
Great, this will help a lot.

I know how to iterate through items in a folder,
however I am concerned with being able to do it from multiple folders
in IMAP email accounts.  Can these be referenced as well from CDO or
the regular Outlook Object Model?

Thanks



Quote:
> 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



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



Mon, 05 Aug 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Extracting an email address from a form email

2. Split or Extract UserName from Email Address!

3. extract the senders email address to a text file

4. Need a program to extract email addresses from MS Outlook 2000 folders/messages

5. Macro to extract sender's address from email message

6. Extracting email address from "From:" field

7. How to extract email address

8. How to extract email address from sender

9. extracting email addresses from text file

10. Extracting all email address tokens from a document

11. **Extract email address from text file**

12. Extract email addresses in an outlook object?

 

 
Powered by phpBB® Forum Software