2016-12-23 83 views
-2

我使用SmtpClient發送電子郵件這樣C#SMTP客戶端,設置發送從參數

MailMessage mail = new MailMessage("[email protected]", "[email protected]", "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); 

這是工作的罰款,我收到郵件,但我收到來自emailAccount地址變量電子郵件。我想收到來自郵件的'From'字段的電子郵件,例如[email protected]

是否有可能?

+0

上[此]所選擇的答案(http://stackoverflow.com/questions/4243300/setting-a-different-from-address-for- mail-via-gmail-using-c-sharp?rq = 1)問題暗示GMail的SMTP服務器不允許更改From字段。 – Martheen

回答

0

你可以做這樣的事情。

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

欲瞭解更多詳情,請參閱。

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/

+0

我看到用於發送電子郵件的電子郵件地址,但沒有看到HTML表單中from字段中輸入的用戶的電子郵件地址。 – Waleed

+0

對不起,但我沒有得到你.. – Bharat

+0

你能解釋更深的.. – Bharat

相關問題