Solved

Get sender email address Outlook.MailItem

Posted on 2001-07-23
5
1,326 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
OK thanks. Now I found it to.  Looks like MS has a small improvement to make here.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now