1
votes

I was trying to send from a aspx page a mail message using the smtp gmail (we are google apps customers and I tried with a paid account and with a free gmail...) I was able to send the messagge setting credentials, port, ssl, etc. but what is wrong is the From address of the message. Indeed, the mail is coming always from the address of the auth user and not from what I set in the msg.From property...

Eg. the mail arrives with from "[email protected]" and not from [email protected]

MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]", "sender name");
msg.To.Add(new MailAddress("[email protected]","recipient name"));
msg.Subject = "subject";
msg.Body = "some body";

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "*******");
smtp.EnableSsl = true;

smtp.Send(msg);

Is there a setting to avoid this ?

thanks in advance

Sandro

1

1 Answers

0
votes

Check the message headers. Depending on your email client, here's the instructions how to reach them: https://support.google.com/mail/answer/22454?hl=en

You'll see, that FROM field is only for indication of the sender's name. It can be ignored by email client, especially, if it contains address different than real sender's address.