2010-09-08 64 views
7

我如何添加一個不同的電子郵件,然後在ReplayTo字段發件人? 似乎MailMessage.ReplyTo已被棄用,所以我試圖用ReplyToList代替。asp.net mail add ReplyTo

但它告訴我,

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

回答

22

不能設置它提升到一個全新MailAddressCollection,但是你可以直接添加到現有MailAddressCollection,如下所示:

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

更多的檢查[這](http://stackoverflow.com/questions/21436827/unable-to-add-reply-to -in-郵件報頭-C-尖銳) – stom 2015-11-02 15:05:37

4

S因斯的ReplyToList是一個只讀屬性,你可以做的唯一途徑是:

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