2015-08-13 18 views
1

美好的一天,我使用ASP.net和SMTP梅勒SMTP郵件與ASP.net錯誤5.5.1需要驗證

我的繼承人問題初學者,我總是會遇到這樣的錯誤,當我從發送電子郵件我當地 和搜查,並試圖繞過球網的解決方案,但沒有這麼幸運, 我希望有人指出什麼碼我需要和在那裏我遇到這個errror

Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" 

繼承人我的代碼:

protected void btnSendEmail_Click(object sender, EventArgs e) 
     { 
      // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0 
      // System.Net.Mail.SmtpClient is the alternate class for this in 2.0 
      SmtpClient smtpClient = new SmtpClient(); 
      MailMessage message = new MailMessage(); 

      try 
      { 
       MailAddress fromAddress = new MailAddress(txtEmail.Value, txtName.Value); 
       smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); 
       // You can specify the host name or ipaddress of your server 
       // Default in IIS will be localhost 
       smtpClient.Host = "smtp.gmail.com"; 
       smtpClient.EnableSsl = true; 
       //Default port will be 25 
       smtpClient.Port = 25; 
       smtpClient.UseDefaultCredentials = false; 
       //From address will be given as a MailAddress Object 
       message.From = fromAddress; 

       // To address collection of MailAddress 
       message.To.Add("[email protected]"); 
       message.Subject = txtSubject.Value; 

       // CC and BCC optional 
       // MailAddressCollection class is used to send the email to various users 
       // You can specify Address as new MailAddress("[email protected]") 
       message.CC.Add("[email protected]"); 

       // You can specify Address directly as string 
       message.Bcc.Add(new MailAddress("[email protected]")); 

       //Body can be Html or text format 
       //Specify true if it is html message 
       message.IsBodyHtml = false; 

       // Message body content 
       message.Body = txtaMessage.Value; 
       message.BodyEncoding = System.Text.Encoding.UTF8; 
       message.HeadersEncoding = System.Text.Encoding.UTF8; 
       // Send SMTP mail 
       smtpClient.Send(message); 

       lblSuccess.Text = "Email successfully sent."; 
      } 
      catch (Exception ex) 
      { 
       lblSuccess.Text = "Send Email Failed."; 
      } 
     } 
+0

嘗試添加'smtp.UserDefaultCreadential = true'和chage p或到587 – kulotskie

+0

@kulotskie在閱讀本文後嘗試過,仍然無法正常工作,同樣的錯誤顯示 –

+0

您能指定什麼是錯誤嗎? – kulotskie

回答

1

試試這個參考ASP Simple SMTP for C# and VB它可以幫我很多可能smtp問題

+0

沒有工作,該方法必須太老以至於無法在實體框架4.0上工作 –

+0

使用VS2015和IM使用該代碼及其工作100% – kulotskie

+0

baka sa email mo na mismong gamit yan kc sakin nag wowork naman sya ee – kulotskie

1
+0

@enrique Gil May gmail阻止您發送電子郵件。 –

+0

謝謝先生!是的,我被Gmail阻止,因爲允許安全性較低的應用程序未啓用!謝謝 ! –

2

我試圖做一個簡單的代碼來發送電子郵件試試這個

MailMessage mm = new MailMessage(); mm.From = new MailAddress("fromEmail"); mm.To.Add("toEmail"); mm.CC.Add("ccEmail"); mm.Subject = "StringSubject"; mm.Body = "BodySubject"; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential(); NetworkCred.UserName = "UsernameString"; NetworkCred.Password = "PasswordString"; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; try { smtp.Send(mm); } catch (Exception) { }

0

後藤的Gmail帳戶,然後選擇 關聯的應用&網站 允許不夠安全的應用:ON(如果這是關閉你不能發送郵件通過應用程序,或您的網站)

相關問題