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

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

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

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

Tags:

.Net

Email