2010-09-08 24 views
7

Tôi làm cách nào để thêm một email khác sau đó người gửi trong trường ReplayTo? Có vẻ như MailMessage.ReplyTo không được dùng nữa nên tôi đang cố sử dụng ReplyToList để thay thế.asp.net mail thêm ReplyTo

Nhưng nó nói với tôi rằng

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

Đây là mã của tôi cho đến nay:

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

Trả lời

22

Bạn không có thể thiết lập nó vào một hoàn toàn mới MailAddressCollection, nhưng bạn có thể thêm trực tiếp đến số hiện tại MailAddressCollection, như sau:

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

để kiểm tra hơn [này] (http://stackoverflow.com/questions/21436827/unable-to-add-reply-to -in-mail-header-c-sharp) – stom

4

S Ince các ReplyToList là một tài sản chỉ đọc, cách duy nhất bạn có thể làm là:

mail.ReplyToList.Add(new MailAddress("[email protected]")); 
mail.ReplyToList.Add(new MailAddress("[email protected]")); 
Các vấn đề liên quan