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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="790d1c0a0d390d1c0a0d571a1614">[email protected]</a>");
 MailMessage mail = new MailMessage(senderEmail,usr.Email,"subject","message");
 mail.ReplyToList = reply;
 var smtp = new SmtpClient();
 smtp.Send(mail);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdc9d8cec9fdc9d8cec993ded2d0">[email protected]</a>");
var smtp = new SmtpClient();
smtp.Send(mail);

Method 2

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

mail.ReplyToList.Add(new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbaaa9a88bb3b2b1e5a8a4a6">[email protected]</a>"));
mail.ReplyToList.Add(new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="06626360466764652865696b">[email protected]</a>"));


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x