asp.net邮件添加ReplyTo

时间:2010-09-08 11:02:18

标签: asp.net email smtp

如何在ReplayTo字段中添加与发件人不同的电子邮件? 似乎{@ 1}}已弃用,因此我尝试使用MailMessage.ReplyTo

但它告诉我

ReplyToList

到目前为止,这是我的代码:

Property or indexer 'System.Net.Mail.MailMessage.ReplyToList' cannot be assigned to -- it is read only

2 个答案:

答案 0 :(得分:24)

您无法设置为全新MailAddressCollection,但您可以直接添加到现有MailAddressCollection,如下所示:

MailMessage mail = new MailMessage(senderEmail,usr.Email,"subject","message");
mail.ReplyToList.Add("test@test.com");
var smtp = new SmtpClient();
smtp.Send(mail);

答案 1 :(得分:4)

由于ReplyToList是一个只读属性,因此唯一可以做的方法是:

mail.ReplyToList.Add(new MailAddress("abc@xyz.com"));
mail.ReplyToList.Add(new MailAddress("def@abc.com"));