2016-09-21 67 views
0

服務器響應是:請在您的郵件客戶端中打開SMTP身份驗證。郵箱不可用。服務器響應是:請在您的郵件客戶端中啓用SMTP身份驗證

我使用某些其他服務器的SMTP細節,我的代碼託管在其他某個服務器上。當我嘗試發送郵件時它給我的錯誤,如下SMTP認證的:

郵箱無法使用。服務器響應是:請在您的郵件客戶端打開SMTP身份驗證。

System.Net.Mail.SmtpFailedRecipientsException:無法發送給所有 收件人。 ---> System.Net.Mail.SmtpFailedRecipientException:郵箱 不可用。服務器響應是:請在您的郵件客戶端中啓用SMTP 身份驗證。

Here is my code: 



public void SendIntimation() 
      { 
       try 
       { 
        string strBody = MessageBody(); 
        string strToEmail = txtEmail.Text.ToString(); 
        string strBcc = "[email protected]"; 
        MailMessage(strToEmail, strBcc, "Thank you for Register with us", strBody); 
       } 
       catch (Exception ex) 
       { 
        Response.Write(ex); 
       } 
      } 

     protected string MessageBody() 
       { 
        string strBody = "Test 123"; 
        return strbody(); 
       } 
    public void MailMessage(string strMailTo, string strMailBcc, string strSubject, string strBody) 
      { 
     try 
       { 
        MailMessage mailMsg = new MailMessage(); 
        mailMsg.From = new MailAddress("[email protected]", "test"); 
        mailMsg.To.Add(strMailTo); 
        //mailMsg.CC.Add(strMailCC); 
        mailMsg.Bcc.Add(strMailBcc); 
        mailMsg.Subject = strSubject; 
        mailMsg.Body = strBody; 
        mailMsg.Priority = MailPriority.Normal; 
        mailMsg.IsBodyHtml = true; 
        SmtpClient mailSmtp = new SmtpClient(); 
        mailSmtp.Host = "domain.com"; 
        mailSmtp.Port = 25; 
        mailSmtp.EnableSsl = true; 
        mailSmtp.Timeout = 90000; 
        mailSmtp.DeliveryMethod = SmtpDeliveryMethod.Network; 
        mailSmtp.UseDefaultCredentials = true; 
        NetworkCredential basicCredential = new 
       NetworkCredential("[email protected]", "password", 
       "domain.com");     
       } 
       catch (Exception ex) 
       { 
        Response.Write(ex); 
       } 
    } 
+0

'UseDefaultCredentials'應該是'FALSE',你需要'mailSmtp.Credentials = basicCredential;' –

+0

此外,你需要要轉到您的Gmail帳戶,請轉到設置,然後啓用POP3/SMTP訪問我們的帳戶 –

+0

您好@AlexK。,這是一個錯字錯誤UseDefaultCredentials爲false。 – Abhi

回答

0

嘗試的基本方法,並從那裏工作了:

using System; 
    using System.Windows.Forms; 
    using System.Net.Mail; 

    namespace WindowsApplication1 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      MailMessage mail = new MailMessage(); 
      SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); 

      mail.From = new MailAddress("[email protected]"); 
      mail.To.Add("to_address"); 
      mail.Subject = "Test Mail"; 
      mail.Body = "This is for testing SMTP mail from GMAIL"; 

      SmtpServer.Port = 587; 
      SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password"); 
      SmtpServer.EnableSsl = true; 

      SmtpServer.Send(mail); 
      MessageBox.Show("mail Send"); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
     } 
    } 
} 
} 
相關問題