Automatically setting the ‘From’ address of a new Outlook message
Posted by benchristian on December 18, 2005
Setting an alternate reply address is particularly useful if you are using a mail enabled public folder or distribution list for a group of users and would like the replies to messages that they send to go to the group smtp address instead of the sender’s mailbox.
There are a several ways to set the reply address for a new message. The first two methods that I will cover are acheived using a custom form. The other method is to set the address programmatically by using vbscript (or another language).
Custom Form methods:
There are 2 different ways to set the reply address using a custom form; both methods have slightly different results. The first method is to simply populate the ‘from’ field with the address that you’d like replies to be sent to. When using this method, the recipient will clearly see that the message has a different ‘from’ address and, as expected, when they hit reply their mail client will address the message to the ‘from’ address.
The second method is to click on the options button for the new message and enter an address in the “have replies sent to:” field. This method preserves the sender’s name, but sets a different reply address. The recipient will see that the message was sent by the sender, but when they hit reply the mail client will address the message to an alternate address.
With both of these methods you need to compose a new message, set the required options and then publish the item as a custom form. You can then use that custom form when you wish to send a message with the alternate reply address. There is a way that you can programmatically create a new message based a custom form; I promise I’ll post that soon.
Custom forms have their limitations however. For a start, the form needs to be published somewhere first; either in the organisational forms library, personal forms library, or a folder. Forms in the local forms cache are also prone to corruption and custom forms in general can be fiddly. Therefore the custom form method is not my preferred method.
Scripted Method (vbscript)
There are few different ways to make it easy for users to click a button to compose their message with the alternate reply address. You could write some VBA code and assign a toolbar button to it; when the users want to send a message using the alternate reply address they simply click the toolbar button. Another approach is to create an html folder homepage for a folder or public folder. In the html code, you can create a button to run some vbscript code to create the message and set the reply address (see below). The advantage to using a public folder homepage is that you avoid having to copy the VBA code to each workstation and manually creating a toolbar button. You can extend the concept by using the Outlook View Control(OVC) in your HTML homepage so that you have a ‘New Message’ button, and directly below have the contents of the public folder displayed in the OVC. The Outlook View Control is beyond the scope of this entry but because it’s so useful it’s on my list of blog topics!
When I first attempted to set the reply address using vbscript (before I downloaded the object model map!) I was trying to set the reply address using the wrong property. I tried two properties first: the SenderName and SenderEmailAddress properties. When I tried to set these properties with vbscript I would receive an error message stating “property is read-only“. If you refer to the object model you’ll see that these are in fact read-only.
The correct property to assign a reply address is the SentOnBehalfOfName property. I’ll admit that when I first saw this property I didn’t try it straight away as I assumed that it would have been read-only too based on the fact that the name of the property is in past tense (SentOnBehalfOfName). The SentOnBehalfOfName sets the ‘from’ field in the new message, so using this method has the same effect as the first custom form method above.
Here is an example of how create a new outlook mail item with an alternate reply address:
Set OlApp = CreateObject("Outlook.Application")
Set NewMessage = olApp.CreateItem(0)
NewMessage.SentOnBehalfOfName = "firstname.lastname@example.org"
if you are scripting or programming with Outlook 2003, I recommend that you download the Outlook 2003 object model map from the microeye website (http://www.microeye.com/resources/code.htm).