如何在ReplayTo字段中添加与发件人不同的电子邮件?
似乎MailMessage.ReplyTo已弃用,因此我尝试使用ReplyToList.
似乎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);