tags:

views:

215

answers:

3

I want to set the ReplyTo value for a .NET MailMessage.

MailMessage.ReplyTo Property:

ReplyTo is obsoleted for this type. Please use ReplyToList instead which can accept multiple addresses.

MailMessage.ReplyToList Property:

Gets or sets the list of addresses to reply to for the mail message.

But, ReplyToList is ReadOnly.

I've tried to use the MailMessage.Headers property like this:

mail.Headers.Add("Reply-To", "[email protected]");

as described here: System.Web.Mail, OH MY!

But, that doesn't seem to work.

How do I set the value(s) of the MailMessage's ReadOnly property ReplyToList?

+6  A: 

ReplyToList is an instance of MailAddressCollection which exposes Add method.

To add a new address you can simply pass address as string

  message.ReplyToList.Add("[email protected]");
Giorgi
Of course. Thank you.
Zack Peterson
+1  A: 

You cannot say

message.ReplyToList = new MailAddressCollection();

To create a new collection. However, adding to the existing collection is what you want to do.

message.ReplyToList.Add(new MailAddress("[email protected]"));
Anthony Pegram
Makes sense. Thank you.
Zack Peterson
A: 

I used the MailMessage.Sender property instead.

mail.Sender = new Mail.MailAddress("[email protected]");
mail.From = new Mail.MailAddress("[email protected]", "John Doe");

More info: MailMessage, difference between Sender and From properties

Zack Peterson