Solved

Get sender email address Outlook.MailItem

Posted on 2001-07-23
5
1,349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

717 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