Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mail add ReplyTo

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);
like image 885
Iulian Avatar asked Sep 08 '10 11:09

Iulian


2 Answers

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);
like image 138
Nick Craver Avatar answered Sep 20 '22 16:09

Nick Craver


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]"));
like image 36
Siva Gopal Avatar answered Sep 20 '22 16:09

Siva Gopal