2015-10-06 20 views
2

我試圖以編程方式發送的電子郵件,我不斷收到以下錯誤:發送電子郵件到主機「smtp.gmail.com」總是示數

The remote name could not be resolved: 'smtp.gmail.com'

這是我想要的代碼:

string sender = "[email protected]"; 
string password = "myPwd"; 
string host = "smtp.gmail.com"; 
int port = "587"; 
MailMessage mail = new MailMessage(); 
SmtpClient smtpServer = new SmtpClient(); 
smtpServer.Host = host; 
mail.From = new MailAddress(sender); 
mail.To.Add(recipient); 
mail.Subject = emailSubject; 
mail.Body = body; 
mail.IsBodyHtml = true; 
smtpServer.Port = port; 
smtpServer.Credentials = new NetworkCredential(sender, password); 
smtpServer.EnableSsl = true; 
smtpServer.Send(mail); 

我總是嘗試,但我不明白髮生了什麼問題。誰能幫忙?

+1

你能從'命令prompt' ping通'smtp.gmail.com'?你知道命令提示符是什麼嗎? –

+0

'ping smtp.gmail.com'然後輸出爲** Ping請求找不到主機smtp.gmail.com。請檢查名稱並重試** –

+0

'smtp.live.com'!='smtp.gmail.com' .... –

回答

0

谷歌改變了您需要更改帳戶設置,安全策略描述here

相關問題