-1

I am using SmtpClient to send email like this

MailMessage mail = new MailMessage("email-from@gmail.com", "email-to@gmail.com", "Contact from " + emailFrom, text);
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(emailAccount, accountPass);
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Send(mail);

This is working fine, I am receiving emails but I receive email from emailAccount address variable. I want to recieve emails from the 'From' field of message i.e email-from@gmail.com

Is it possible?

Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
Waleed
  • 1,097
  • 18
  • 45
  • The chosen answer on [this](http://stackoverflow.com/questions/4243300/setting-a-different-from-address-for-mail-sent-via-gmail-using-c-sharp?rq=1) question imply GMail's SMTP server doesn't allow changing the From field. – Martheen Dec 23 '16 at 10:16

1 Answers1

0

You can do something like these.

mail.From  = fromEmailAddress; // Your variable that contains from address

for more details see.

https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage(v=vs.110).aspx

Sending Email to multiple Recipients with MailMessage

http://www.c-sharpcorner.com/article/smtpmail-and-mail-message-send-mails-in-net/

Community
  • 1
  • 1
Bharat
  • 5,869
  • 4
  • 38
  • 58
  • I see the email address which was used to send the email but not that which user types in the from field in the HTML form. – Waleed Dec 23 '16 at 05:03