Outlook Developer Home
Outlook Programmer's Library
 
Outlook Technologies
Outlook Forms
Languages
Samples
Other Technologies

 

 

To get the sender's address from an Outlook mail message

Microsoft Outlook provides a SenderName property for the MailItem object, but no obvious way to get the sender's e-mail address. Even though Help suggests that the sender is part of the Recipients collection, with Type = olOriginator (0), it doesn't actually work that way. 

We provide two functions here -- one to get the From address from a message and a second to get the Reply To address. While these are usually the same address, they may differ. In general, you need the From address if you're performing tasks on incoming messages depending on who sent them or if you want to add a sender to the Contacts folder and be able to use the Look up Contact feature on future messages from that person. You need the Reply To address if you're planning to send messages to the sender. 

Both routines are intended to handle just SMTP addresses. I have not made any effort to handle non-SMTP addresses. This could be done by examining the Type property of the Recipient or Sender (Sender is a CDO AddressEntry object.) and adding code to include the type for non-SMTP addresses, using the syntax [<type>:<address>]. 

The code below is for VBScript. You can also download a VB/VBA module for Outlook 2000 that demonstrates both functions with a ShowAddresses subroutine that writes the addresses to the Immediate window.  

Get From Address | Get Reply Address | Get From Address with Redemption | More Information

Get From Address (CDO)

This VBScript routine requires CDO, which is not included in all Outlook installations.  Note that, if the Outlook E-mail Security Update and Outlook 2000 CDO Security Update are installed on the machine and the user does not click Yes when the prompt about accessing addresses appears, an error results. This routine handles that error with a popup to the user and causes GetFromAddress() to return a blank address. 

If the sender is an Exchange Server user, this routine will provide the Exchange X.400-style address, not the SMTP address. If you need the SMTP address, see Get the SMTP address of the originator of a message. Back to Top

Get Reply Address (Outlook only)

This Outlook VBScript function returns the Reply To address of a message by creating a dummy reply messages. Note that, if the Outlook E-mail Security Update is installed on the user's system and the user does not click Yes when the prompt about accessing addresses appears, an error results. This routine handles that error with a popup to the user and causes GetReplyToAddress() to return a blank address. 

 Back to Top

Get From Address (Redemption)

Both of the two methods above will trigger the address book security prompt if the Outlook Email Security Update or Outlook 2002 is installed. One way to avoid the prompts is to use the third-party Redemption library This Outlook VBScript function returns the address of the sender of an Outlook MailItem (objMsg) in SMTP name@domain.dom format, even if the sender is an Exchange Server user in the same organization. You must first download and install the Redemption library.

 Back to Top

More Information

Code samples for changing the From or Reply address:

   
2002-7 TurtleFlock, LLC
All right reserved.
About OutlookCode.com

Send comments to webmaster@outlookcode.com

Designed and Implemented by TerraLink USA 

FrontPage Integration
by RobsonDesignWorks

 
 
get Sue's code | forums | share your own code | registration