2013-09-24 31 views
0

我能夠從LocalHost成功發送電子郵件。 託管我的網站後,我無法發送。 以下是錯誤:無法使用asp.net&C#從遠程服務器發送電子郵件?

System.Net.Mail.SmtpException:SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.7.0必須首先發出STARTTLS命令。 ha10sm40374374pbc.23 - gsmtp

任何人都可以幫助我解決這個問題。

下面是代碼:

public void SendMail(string ToMail, string subject, string Message) 
     { 
        // Gmail Address from where you send the mail 
      string fromAddress = "[email protected]"; 
        // any address where the email will be sending 
      //string toAddress = ToMail; 
        //Password of your gmail address 
      const string fromPassword = "********"; 
        // Passing the values and make a email formate to display 
      //string subject = subject; 
      string body = "\n\n"+Message; 
        // smtp settings 
        var smtp = new System.Net.Mail.SmtpClient(); 
        { 
         smtp.Host = "smtp.gmail.com"; 
         smtp.Port = 587; 
         smtp.EnableSsl = true; 
         smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
         smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
         smtp.Timeout = 20000; 

        } 
        // Passing values to smtp object 
        smtp.Send(fromAddress, ToMail, subject, body); 


     } 
+0

您能顯示您用來發送電子郵件的代碼嗎? –

+0

請添加smtp.UseDefaultCredentials = true並檢查 –

+0

即使在添加UseDefaultCredentials = true後也不起作用。 – user2667871

回答

0

谷歌發送郵件與我選擇的這是我唯一的選擇subjact 「阻止可疑跡象」。 然後更改了Gmail密碼並在應用程序中使用它。 現在能夠從生產服務器發送郵件...

相關問題