0
votes
var client = new SmtpClient("smtp.gmail.com", 587) 
{
    Credentials = new NetworkCredential("[email protected]", "supersecretpassword"),
    EnableSsl = true
};

MailMessage message = new MailMessage(new MailAddress(sender), 
                                      new MailAddress(recepient));
//message.From = new MailAddress(sender);
message.IsBodyHtml = true;
// message.To.Add(new MailAddress(recepient));
//message.ReplyToList.Add(new MailAddress(sender));
message.Subject = "subject";
message.Body = "title";

client.Send(message);

I'm sending an email using the code above, however, if the recepient decides to reply to the email, i want the to reply to the Adress supplied in the sender parameter, but when i receive the email, the From field gives the address of the [email protected] provided in the smtp info.

I tried setting the replyto, replytolist and from properties in MailMessage, but it doesn't cahnge anything.

With the reply to i could see the sender address in "ReplyTo" in gmail, but the default receiver if i pressed reply is still [email protected]

Am i not supposed to be able to change this for some reason, or am i missing something?

EDIT i'm suspecting this has to do with using a temporary gmail as smtp server, but i can't find any confirmation to this.

2

2 Answers

0
votes

ReplyTo is deprecated, ReplyToList is a correct way.

If you think this is a gmail related problem try with another smtp (for example sendgrid )

Keep in mind that gmail uses Sender and From differently in case of "fake" account as you can read here

0
votes

https://stackoverflow.com/a/3872880/744610

according to this answer it is because i'm using gmail as smtp server, and gmail doesn't allow changing the From/sender properties of an email, to avoid spam