System.Net.Mail.SmtpException:不允许使用邮箱名称.

使用SmtpClient发送邮件的时候,出现了如题错误。

解决方案:

将  SmtpClient.UseDefaultCredentials  属性设置为 true 。

官方文档说明:

Some SMTP servers require that the client be authenticated before the server sends e-mail on its behalf. Set this property to truewhen this  SmtpClient  object should, if requested by the server, authenticate using the default credentials of the currently logged on user. For client applications, this is the desired behavior in most scenarios.

Credentials information can also be specified using the application and machine configuration files. For more information, see  <mailSettings> Element (Network Settings) .

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. If the  UseDefaultCredentials  property is set to false and the  Credentials  property has not been set, then mail is sent to the server anonymously.

 

谷歌翻译:

一些SMTP服务器要求客户端在服务器代表它发送电子邮件之前进行认证。 如果此服务器请求,此SmtpClient对象应使用当前登录用户的默认凭据进行身份验证,请将此属性设置为true。 对于客户端应用程序,这是大多数情况下所需的行为。

凭证信息也可以使用应用程序和机器配置文件来指定。 有关更多信息,请参阅<mailSettings>元素(网络设置)。

如果UseDefaultCredentials属性设置为false,则在连接到服务器时,Credentials属性中设置的值将用于凭据。 如果UseDefaultCredentials属性设置为false,并且尚未设置Credentials属性,则邮件将匿名发送到服务器。

 

官方文档:https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.smtpclient.usedefaultcredentials?view=netframework-4.7.1

 

转载于:https://www.cnblogs.com/mlocvery/p/8177332.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值