无法使用SmtpClient发送邮件

编程入门 行业动态 更新时间:2024-10-19 08:54:45
本文介绍了无法使用SmtpClient发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用SmtpClient类发送邮件,但是它不起作用.代码:

I want to send mail using SmtpClient class, but it not work. Code:

SmtpClient smtpClient = new SmtpClient(); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential(obMailSetting.UserName, obMailSetting.Password); smtpClient.Host = obMailSetting.HostMail; smtpClient.Port = obMailSetting.Port; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = obMailSetting.Connect_Security;//true //smtpClient.UseDefaultCredentials = true;//It would work if i uncomment this line smtpClient.Send(email);

它引发异常:

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

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

我确定用户名和密码正确.我的代码有什么问题吗?谢谢.

I'm sure that username and password is correct. Is there any problem in my code? Thanks.

推荐答案

服务器响应 5.7.1客户端未通过身份验证,但前提是您未设置 UseDefaultCredentials 改为 true .这表明您使用的 NetworkCredential 实际上是错误的.

The server responds with 5.7.1 Client was not authenticated but only if you do not set UseDefaultCredentials to true. This indicates that the NetworkCredential that you are using is in fact wrong.

用户名或密码错误,或者您需要指定域?您可以使用其他构造函数来指定域:

Either the user name or password is wrong or perhaps you need to specify a domain? You can use another constructor to specify the domain:

new NetworkCredential("MyUserName", "MyPassword", "MyDomain");

或者您指定的用户没有必要的权限在SMTP服务器上发送邮件,但是我希望另一个服务器响应.

Or perhaps the user that you specify does not have the necessary rights to send mail on the SMTP server but then I would expect another server response.

更多推荐

无法使用SmtpClient发送邮件

本文发布于:2023-11-17 12:18:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送邮件   SmtpClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!