English 中文(简体)
SMTP 服务器需要安全连接或客户端未经认证。 服务器响应是: 5. 5.1 身份验证
原标题:The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
  • 时间:2012-05-22 08:55:57
  •  标签:
  • c#

我有一个问题, 当我通过此代码发送邮件时, 出现错误, “ SMTP 服务器需要安全连接, 或者客户端没有认证 。 服务器响应是: 5. 5.1 需要验证 。 ”

我的代码是:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{

    MailMessage mail = new MailMessage();
    mail.To.Add("[email protected]");
    mail.From = new MailAddress("[email protected]");
    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 = 25;
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "xyz");
    smtp.EnableSsl = true;
    smtp.Send(mail);


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

}
问题回答

Google may prevent an application from accessing your account
Here you can enable applications to access google account with your credentials:

https://counts.google.com/Display Unlock Captcha>>https://counts.google.com/Display Unlock Captcha

我认为你应该设置 < a href=>" "http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.use defaultcrecials.aspx" rel="nofollow" > Use DefaultCrecials 虚假,因为您定义了连接的证书 。

Set this property to true when this SmtpClient object should, if requested by the server, authenticate using the default credentials of the currently logged on user.

[.]

If the UseDefaultCredentials property is set to false, then the value set in the Credentials property will be used for the credentials when connecting to the server

Try the port 587(it worked for me ) and also set UseDefaultCredentials to false. Set this and try to send the mail

我认为你用错港口了

您应该使用465

http://support.google.com/mail/bin/meeting.py?hl=en& amp;remed=13287

欢呼

端口并不真正重要, 因为系统. Net. Mail 不支持隐含的 SSL, 换句话说, 它完全忽略了“ Port” 参数 。

我试图通过 SQL Server 2012 数据库邮件来设置这个信息, 并且收到同样的信息。

我从来没有能够用我的主要 g 邮件账户来运作,这个账户使用双重认证,即使使用了应用程序特定密码。 我最后尝试了我的第二个账户,这个账户没有双重认证,并且立即起作用。因此,对于那些无法使用上述解决方案之一工作的人,请使用标准的 auuth g 邮件账户尝试。

微软国家不推荐 SmtpClient 。 您应该使用 MailKit, 它肯定会有效 。

< a href=>https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netframework-4.0' rel=“不跟随 Nofollown noreferrer'>https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netframform-4.0

< parger> 我们不建议您使用 SmtpClient 类进行新开发, 因为 SmtpClient 不支持许多现代协议 。 使用 MailKit 或其他库。 更多信息, 请查看 SmtpClient 不应该在 GitHub 上使用 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签