asp.net 邮件添加 ReplyTo

发布于 2024-09-18 17:50:33 字数 661 浏览 7 评论 0原文

如何在 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("[email protected]");
 MailMessage mail = new MailMessage(senderEmail,usr.Email,"subject","message");
 mail.ReplyToList = reply;
 var smtp = new SmtpClient();
 smtp.Send(mail);

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("[email protected]");
 MailMessage mail = new MailMessage(senderEmail,usr.Email,"subject","message");
 mail.ReplyToList = reply;
 var smtp = new SmtpClient();
 smtp.Send(mail);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

是伱的 2024-09-25 17:50:33

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

MailMessage mail = new MailMessage(senderEmail,usr.Email,"subject","message");
mail.ReplyToList.Add("[email protected]");
var smtp = new SmtpClient();
smtp.Send(mail);

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("[email protected]");
var smtp = new SmtpClient();
smtp.Send(mail);
美羊羊 2024-09-25 17:50:33

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

mail.ReplyToList.Add(new MailAddress("[email protected]"));
mail.ReplyToList.Add(new MailAddress("[email protected]"));

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

mail.ReplyToList.Add(new MailAddress("[email protected]"));
mail.ReplyToList.Add(new MailAddress("[email protected]"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文