1

I have difficult to change the "From" attribute value for the actual sender address, even I add it in the code, as below: (never mind what is added the From header shows my address, that I connect to SMTP server)

MailMessage m = new MailMessage(); 
SmtpClient sc = new SmtpClient();
m.From = new MailAddress(from, "Display name From"); 
m.To.Add(new MailAddress(to, "Display name To"));
m.Subject = "Test1"; 
m.IsBodyHtml = true; 
m.Body = " This is a Test Mail";
m.ReplyTo = new MailAddress(from);
MailAddress bcc = new MailAddress(to);
m.Bcc.Add(bcc);
sc.Host = "smtp.gmail.com"; 
sc.Port = 587;
sc.Credentials = new System.Net.NetworkCredential("google@gmail.com", "password");
sc.EnableSsl = true;
sc.Send(m);

I will appreciate if anybody will help me with the issue

1 Answers1

2

This is a gmail problem, you cannot change the from address when using the gmail smtp (at least the non business gmail accounts). It will always set your gmail address as from address.

edit: you can use addresses you have configured in your gmail settings as "send as"
https://support.google.com/a/answer/22370?hl=en

fuchs777
  • 993
  • 1
  • 14
  • 30
  • "this is a gmail problem" - It's not a "problem" - many SMTP servers will not allow you to send with a From address other than that associated with the credentials used to access the server. This is a good thing: it prevents you from impersonating other people when sending mail. – Joe Oct 09 '13 at 08:13
  • whether it is good or not, it's the cause of his problem. (might be my english is not good enough to use the correct words to describe this) – fuchs777 Oct 09 '13 at 08:18