Solved

Get sender email address Outlook.MailItem

Posted on 2001-07-23
5
1,335 Views
Last Modified: 2012-08-13
How do I find the sender email?

I can get the sender name with the .SenderName property.  But how do I get the email address?

I am using the outlook.mailitem

0
Comment
Question by:nicolas_image
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:sdm395
ID: 6311581
Try looking at the recipients collection of the mailitem.  Loop through until you find one with type = olOriginator - this will be the sender.  You can then use the .address property.

Hope this helps
0
 

Author Comment

by:nicolas_image
ID: 6311689
I have tried the following code:

- - - - - CUT - - - -
Set MailItem = oSelection.Item(Counter)
With MailItem
  If Not (.Recipients Is Nothing) Then
    Set RecipList = .Recipients
    For Each Recip In RecipList
      Select Case Recip.Type
        Case olTo
           msgbox "TO: " & Recip.adress
        Case olCC
           msgbox "CC: " & Recip.adress
        Case olBCC
           msgbox "BCC: " & Recip.adress
        Case olOriginator
           msgbox "From: " & Recip.adress
- - - - - CUT - - - - - -

But my code never display the MSGBOX "From:" WHY!!!


0
 

Author Comment

by:nicolas_image
ID: 6311708
I have tried the following code:

- - - - - CUT - - - -
Set MailItem = oSelection.Item(Counter)
With MailItem
  If Not (.Recipients Is Nothing) Then
    Set RecipList = .Recipients
    For Each Recip In RecipList
      Select Case Recip.Type
        Case olTo
           msgbox "TO: " & Recip.adress
        Case olCC
           msgbox "CC: " & Recip.adress
        Case olBCC
           msgbox "BCC: " & Recip.adress
        Case olOriginator
           msgbox "From: " & Recip.adress
- - - - - CUT - - - - - -

But my code never display the MSGBOX "From:" WHY!!!


0
 
LVL 1

Accepted Solution

by:
sdm395 earned 100 total points
ID: 6311755
I found this function on slipstick.com
it takes a mailitem object, and return the 'from' address.  I have tested it and it works fine...however it does a mapi logon each time, so you might need to rework it depending on how you are going to use it.

Function GetFromAddress(objMsg)

  ' start CDO session

  Set objSession = CreateObject("MAPI.Session")

  objSession.Logon , , False, False

 

  ' pass message to CDO

  strEntryID = objMsg.EntryID

  strStoreID = objMsg.Parent.StoreID

  Set objCDOMsg = objSession.GetMessage(strEntryID, strStoreID)

 

  ' get sender address

  On Error Resume Next

  strAddress = objCDOMsg.Sender.Address

  If Err = 80070005 Then

    'handle possible security patch error
  End If

 

  GetFromAddress = strAddress

 

  Set objCDOMsg = Nothing

  objSession.Logoff

  Set objSession = Nothing

End Function


0
 

Author Comment

by:nicolas_image
ID: 6311986
OK thanks. Now I found it to.  Looks like MS has a small improvement to make here.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question