asp.net邮件添加ReplyTo

前端之家收集整理的这篇文章主要介绍了asp.net邮件添加ReplyTo前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在ReplayTo字段中添加与发件人不同的电子邮件
似乎MailMessage.ReplyTo已弃用,因此我尝试使用ReplyToList.

但它告诉我

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

这是我到目前为止的代码

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

解决方法

您不能将其设置为全新的MailAddressCollection,但可以直接添加到现有的MailAddressCollection,如下所示:
MailMessage mail = new MailMessage(senderEmail,"message");
mail.ReplyToList.Add("test@test.com");
var smtp = new SmtpClient();
smtp.Send(mail);
原文链接:https://www.f2er.com/aspnet/247951.html

猜你在找的asp.Net相关文章