1

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
        };
SB2055
  • 12,272
  • 32
  • 97
  • 202
  • are you getting an exception? – Garrett Oct 25 '13 at 00:46
  • nope, it just doesn't let me reply-to the sender – SB2055 Oct 25 '13 at 00:49
  • Have you tried other email clients? Or looking at the email headers received? I wonder if gmail is preventing you from doing this as an anti-spam/spoofing measure: http://stackoverflow.com/a/2668788/945456 – Jeff B Oct 25 '13 at 00:53
  • @JeffBridgman - just checked the headers. I have an email address at hover.com set up, that the app@gmail.com address is sending on behalf of - the SENDER field from all emails is set to the gmail address, while the FROM is set to the hover address, and never the user's address. I wonder if gmail is overwriting the FROM because of this configuration... – SB2055 Oct 25 '13 at 00:59
  • Possible duplicate of [How to change from-address when using gmail smtp server](http://stackoverflow.com/questions/1332510/how-to-change-from-address-when-using-gmail-smtp-server) – Jeff B Jul 14 '16 at 22:09

1 Answers1

2

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.

Community
  • 1
  • 1
Jeff B
  • 8,572
  • 17
  • 61
  • 140