Pergunta

I have a MailMessage that I'm sending with the following:

email.To.Add(new MailAddress(receiver.Email, receiver.Username));
email.From = new MailAddress(sender.Email, "app (on behalf of " + sender.Username + ")");
email.Sender = new MailAddress("app@gmail.com", "App");

The idea is that the email will be sent to the receiver with the sender's email address in the FROM header, so that the receiver can hit "Reply" in their email client, and email the sender directly.

Currently, when I get an email as Receiver, I hit reply to and get app@gmail.com, while the FROM text says (on behalf of), as it should.

Is this not the proper way to set the message up?

In case it matters, my smtpClient:

var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential("app@gmail.com", "Password"),
            EnableSsl = true
        };
Foi útil?

Solução

You're doing it right. But gmail won't let you.

To quote the answer linked to....

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top