System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证

2

本文介绍了System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试从 C# 应用程序发送带有我网站地址的电子邮件.
直到最近,这几个月都运行良好.(也许我的提供者改变了一些东西或者其他人改变了设置)

I'm trying to send email with my website's address from a C# application.
This worked fine for several months until recently. (maybe my provider changes some things or someone else changed settings)

代码如下:

  private void sendEmail(Email invite) {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(smtpServerName);
            mail.From = new MailAddress(emailUsername);

            mail.To.Add(invite.RecipientEmail);
            mail.Subject = invite.MessageSubject;
            mail.Body = invite.MessageBody;

            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
//          SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);
        }  

这是错误:

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

The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.

查看其他问题,我尝试了他们的建议,使 SmtpServer.EnableSsl = true.这根本不起作用.它给出了以下内容:

Looking at other questions I tried what they suggested, to make SmtpServer.EnableSsl = true. This didn't work at all. It gave the following:

System.Net.Mail.SmtpException:服务器不支持安全连接.

System.Net.Mail.SmtpException: Server does not support secure connections.

我猜我应该禁用 SSL 并按照以前的方式使用它.

I'm guessing I should disable SSL and have it the way it was before.

有什么建议可以让电子邮件再次发送工作吗?

Any suggestions how to make email sending work again?

编辑
我试过没有 SmtpServer.UseDefaultCredentials = false;
我尝试将其设置为 true:SmtpServer.UseDefaultCredentials =true;
我尝试将该行与以下 //SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);

推荐答案

该错误消息通常由以下原因之一引起:

That error message is typically caused by one of the following:

  • 连接设置不正确,例如为安全或非安全连接指定了错误的端口
  • 凭据不正确.我会验证用户名和密码组合,以确保凭据正确.

这篇关于System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14