简体   繁体   English

如何修复 System.Net.Mail.SmtpException

[英]How Can I Fix System.Net.Mail.SmtpException

This is Image Of Error Here is Full Problem System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated.这是错误图像这里是完整问题 System.Net.Mail.SmtpException: 'SMTP 服务器需要安全连接或客户端未通过身份验证。 The server response was: 5.7.0 Authentication Required.服务器响应为:需要 5.7.0 身份验证。

    `private void button1_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage(from.Text, to.Text, subject.Text, body.Text);

        SmtpClient client = new SmtpClient(smtp.Text, 587);

        client.Port = 587;
        client.Credentials = new System.Net.NetworkCredential(username.Text, password.Text);

        client.EnableSsl = true;
        client.Send(mail);
        MessageBox.Show("Mail Sent!", "Success", MessageBoxButtons.OK);
    }`

Here is The Code and I tried al Thing please tell How can I Fix it Email Sender这是代码,我试过了,请告诉我如何修复它 Email 发件人

Because you use custom credentials and use authentication (enablessl = true).因为您使用自定义凭据并使用身份验证 (enablessl = true)。 Together with your own login (not default) you need to add:连同您自己的登录名(非默认),您需要添加:

client.UseDefaultCredentials = false;

before setting client.credentials在设置 client.credentials 之前

Otherwise the credentials you filled in won't be used否则您填写的凭据将不会被使用

EDIT: when this line is added as stated before, and there are still authentication problems.编辑:如前所述添加此行时,仍然存在身份验证问题。 Try checking if all of the variables are correct.尝试检查所有变量是否正确。 This can be done using the website: https://www.smtper.net/这可以使用网站完成: https://www.smtper.net/

Technically the variables should be tested before you start programming.从技术上讲,应该在开始编程之前测试变量。

The error you are getting 'The SMTP server requires a secure connection or the client was not authenticated.您收到的错误“SMTP 服务器需要安全连接或客户端未通过身份验证。 The server response was: 5.7.0 Authentication Required.'服务器响应是:需要 5.7.0 身份验证。 means that you aren't using HTTPS and/or can't authenticate using the credentials.表示您没有使用 HTTPS 和/或无法使用凭据进行身份验证。 smtper.net is therefor the best tool of finding out if your credentials are correct.因此,smtper.net 是查明您的凭据是否正确的最佳工具。

Your code seems to be correct on first glance with the exception of adding client.usedeafultcredentials = false.除了添加 client.usedeafultcredentials = false 之外,您的代码乍一看似乎是正确的。 Wich is why I'm assuming the variables you are working with are incorrect.这就是为什么我假设您正在使用的变量不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何正确处理System.Net.Mail.SmtpException? - How to correctly handle System.Net.Mail.SmtpException? 出现错误:-System.net.mail.SmtpException - Getting error:-System.net.mail.SmtpException System.Net.Mail.SmtpException:邮箱不可用 - System.Net.Mail.SmtpException: Mailbox unavailable system.net.mail.smtpException:无法连接到远程服务器? - system.net.mail.smtpException :Unable to connect to the remote server? System.Net.Mail.SmtpException:该地址具有无效的主机名 - System.Net.Mail.SmtpException: The address has an invalid host name System.Net.Mail.SmtpException {“发送电子邮件失败。”} - System.Net.Mail.SmtpException {“Failure Sending Email.”} System.Net.Mail.SmtpException:系统存储不足。 服务器响应如下:4.3.1系统资源不足 - System.Net.Mail.SmtpException: Insufficient system storage. The server response was: 4.3.1 Insufficient system resources 将白名单IP gmail smtp-System.Net.Mail.SmtpException:发送邮件失败 - Whitelist IP gmail smtp - System.Net.Mail.SmtpException: Failure sending mail System.Net.Mail.SmtpException:发送邮件失败。 无法从传输连接中读取数据 - System.Net.Mail.SmtpException: Failure sending mail. Unable to read data from the transport connection 尝试在System.dll中使用smtp'System.Net.Mail.SmtpException'发送电子邮件时出错 - error when trying to send email using smtp 'System.Net.Mail.SmtpException' in System.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM