zoukankan      html  css  js  c++  java
  • 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

    console.log("talk is cheap, show me you code.")
  • 相关阅读:
    C# 参数按照ASCII码从小到大排序(字典序)
    .net平台下C#socket通信 (下)
    net平台下C#socket通信(上)
    使用C#创建Windows服务
    C# EF 批量操作
    消息队列及常见消息队列介绍
    消息队列的4种应用场景
    npm install 安装到指定的目录
    express学习1
    nodejs url
  • 原文地址:https://www.cnblogs.com/mlocvery/p/8177332.html
Copyright © 2011-2022 走看看