asp.net mail add ReplyTo

蓝咒 提交于 2019-12-19 07:04:41

问题


How can i add a a different email then the sender in the ReplayTo field ? Seems MailMessage.ReplyTo is deprecated so I'm trying to use ReplyToList instead.

But it's telling me that

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

Here is my code so far:

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

回答1:


You can't set it to a whole new MailAddressCollection, but you can add directly to the existing MailAddressCollection, like this:

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



回答2:


Since the ReplyToList is a readonly property,the only way you can do is :

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


来源:https://stackoverflow.com/questions/3667006/asp-net-mail-add-replyto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!