How do I assign a value to a MailMessage ReplyTo property?

Solution 1:

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]");

Solution 2:

I like the array init syntax, which will call Add() for you.

var msg = new MailMessage("[email protected]", mailTo) {
    Subject = "my important message",
    Body = this.MessageBody,
    ReplyToList = { mailTo } // array init syntax calls Add()
};
mailClient.Send(msg);

Solution 3:

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]"));

Solution 4:

My answer is not unlike the accepted answers already given. However, I felt it needed to be provided.

var fromEmail = new MailAddress("[email protected]", "Foo Bar");
var replyEmail = new MailAddress("[email protected]", "Foo Example");
var msgEmail = new MailMessage { From = fromEmail };
msgEmail.ReplyToList.Add( replyEmail );