SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。

时间:2012-05-22 09:27:46

标签: c# sql-server-2008 gmail smtp-auth

  

可能重复:
  The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

我运行此代码时出现问题,然后发生错误“SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要验证。”

我的代码是:

代码

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

    MailMessage mail = new MailMessage();
    mail.To.Add("info@msslindia.com");
    mail.From = new MailAddress("info@msslindia.com");
    string body = "<table><tr><td>Company Name:</td><td>" + txt_cname.Text + "</td></tr><tr><td>Address With No.:</td><td>" + txt_addwithno.Text + "</td></tr><tr><td>Contact Person:</td><td>" + txt_conperson.Text + "</td></tr><tr><td>Email Id</td><td>" + txt_email.Text + "</td></tr><tr><td>Description</td><td>" + txt_description.Text + "</td></tr></table>";
    mail.Body = body;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;

    smtp.Credentials = new System.Net.NetworkCredential("info@msslindia.com", "12345");
    smtp.EnableSsl = true;
    smtp.Send(mail);


    txt_cname.Focus();
    txt_cname.Text = "";
    txt_addwithno.Text = "";
    txt_conperson.Text = "";
    txt_email.Text = "";
    txt_description.Text = "";

}

1 个答案:

答案 0 :(得分:10)

您在哪里托管您的网站? Gmail可防止无法识别您帐户的访问权限。尝试执行此代码然后转到gmail,它会询问您是否有来自您的访问权限。允许申请,你​​就完成了。