Solved

Get sender email address Outlook.MailItem

Posted on 2001-07-23
5
1,340 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 74
VB6 Compile Compatibility Issue 4 115
How does CurrentUser work? 10 38
Exit a vb6 apps when a calling it apps closes 15 52
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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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