Search code examples
c#smtpgmail

Sending an SMTP email through GMail with reply support


I am creating a gmail SMTP client like so:

client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential(email, password);
client.Timeout = 20000;

And sending an email like so:

MailMessage msg = new MailMessage();    
msg.From = new MailAddress([email protected]);
msg.To.Add(to);
msg.Subject = subject;
msg.Body = body;
client.Send(msg);

I wish that if someone replies to my email it'll go to the admins email address, not to my application, and also ideally for them not to even know about the existence of the application's email address.

I could have my application forward emails received to the admin, but that's an ugly solution.

I understood from other threads that there's no way to send an email with a "reply to" field.

What I'm wondering is what if I have the admin's email as a "Send mail as" registered account on the application's GMail account.

So through the GMail interface I can send an email as if I'm the admin, can I do this from my c# application?

I know that I can set the from field of the msg sent to the admin's email, but I'm wondering if this is the correct approach, if gmail supports this, and if the email doesn't have more likelihood of ending up in the spam folder.


Solution

  • I have given authority to "Send mail as" in the application e-mail as the admin, and simply editing the "from" field to be sent as the admin's email address appears to be working flawlessly.

    So I guess this is one of those cases that the simplest solution is the correct one.

    Edit: It appears that editing the "from" field doesn't allow you to send from a different address, but what does work is setting up the default email to send emails from as a different email in the GMail "send mail as" options.