2012-04-24 21 views
0

可能重複:
How to use gmail SMTP in ASP.NET form變得異常在發送電子郵件

變得異常,同時發送郵件。 - 根據驗證程序,遠程證書無效。需要解決。 我的代碼是:

public bool mailSender(string toMailId, string uniqueGuid) 
     { 
      try 
      { 
       SmtpClient smtpClient = new SmtpClient(); 
       string linkForConfirm = "orderConfirmation.aspx?id=" + uniqueGuid; 
       string Subject = "Shiv Cart Grocery Shop Confirmation"; 
       string body = " <div style='width:700px; margin:0 auto;'><div style='background-color:#800000; width:700px'>"; 
       body += "</div><div><h2>Shiv Cart Grocery Shop</h2><h3 style='color:#0099FF; width:700px'> Click Below To Confirm Your Order</h3>"; 
       body += "<a href='" + linkForConfirm+ "' id='a' ></a></div></div>"; 
       MailAddress fromMailAddress = new MailAddress("[email protected]", "Shiv Cart"); 
       MailAddress toMailAddress = new MailAddress(toMailId); 
       MailMessage mail = new MailMessage(fromMailAddress, toMailAddress); 
       mail.Subject = Subject; 
       mail.Body = body; 
       mail.IsBodyHtml = true; 
       smtpClient.Host = "smtp.gmail.com"; 
       smtpClient.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["MailSenderUserName"].ToString(), WebConfigurationManager.AppSettings["MailSenderPass"].ToString()); 
       smtpClient.EnableSsl = true; 
       smtpClient.Send(mail); 
       return true; 
      } 
      catch (Exception) 
      { 
       return false; 
      } 
     } 
+0

所以你想只用gmail.com開放中繼? – Bond 2012-04-24 08:29:02

+0

我想你錯過了:smtpClient.SmtpPort = 25; – 2012-04-24 08:29:45

+0

Gmail使用端口587. – Coder 2012-04-24 08:39:15

回答