2011-05-04 137 views
0

Possible Duplicate:
Sending email in .NET through Gmail發送電子郵件使用Gmail SMTP C#

你好,

進出口使用的代碼像下面,但我得到一個錯誤:

"Unable to connect to the remote server" 

MailMessage mail = new MailMessage(); 
     mail.To.Add("[email protected]"); 
     mail.From = new MailAddress("[email protected]"); 
     mail.Subject = "Test Email"; 
     string Body = "<b>Welcome to CodeDigest.Com!!</b>"; 
     mail.Body = Body; 
     mail.IsBodyHtml = true; 
     SmtpClient smtp = new SmtpClient(); 
     smtp.Host = "smtp.gmail.com"; 
     smtp.Port = 587; 
     smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "myPass"); 
     smtp.EnableSsl = true; 
     smtp.Send(mail); 
+3

代碼看起來不錯。您的防火牆很可能阻止該端口上的傳出請求。 – 2011-05-04 13:45:04

+0

嘗試使用端口號465進行SSL連接。 – Joe 2014-01-02 13:24:50

回答

3

你不是同一個電子郵件地址,你」送重新驗證與...你必須添加[email protected]作爲「從」

編輯:由於巴拉R建議,可能你的防火牆基於你得到的錯誤

+0

沒有幫助。任何其他想法? – gruber 2011-05-04 13:46:01

+0

@gruber可能是防火牆 – 2011-05-04 13:49:02