Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get sender email address Outlook.MailItem

Posted on 2001-07-23
5
Medium Priority
?
1,368 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 400 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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