試圖發送一些電子郵件在我的C#應用程序。我支持代理 - 這無疑爲什麼代碼不起作用。這是我到目前爲止有:通過代理使用Gmail發送電子郵件smtp
App.Config中:
<system.net>
<defaultProxy enabled="false">
<proxy proxyaddress="xxx.xxx.xxx.xxx"/>
</defaultProxy>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" port="587"/>
</smtp>
</mailSettings>
</system.net>
代碼:
var username = "...";
var password = "...";
var fromEmail = "...";
var toEmail = "...";
var body = "Test email body";
var subject = "Test Subject Email";
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential(username, password),
EnableSsl = true
};
try
{
client.Send(fromEmail, toEmail, subject, body);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
每次我得到System.Net.WebException:遠程名稱不能解決:'smtp.gmail.com'
在哪裏/如何開始調試?
可能是你正在查看的答案可在https://stackoverflow.com/questions/19446001/send-smtp-mail-from-gmail-live-aol-or-yahoo-accounts-when-my-pc- is-connected-v/42719817#42719817 – dbw 2017-06-05 12:22:58