<i id='ngYWr'><tr id='ngYWr'><dt id='ngYWr'><q id='ngYWr'><span id='ngYWr'><b id='ngYWr'><form id='ngYWr'><ins id='ngYWr'></ins><ul id='ngYWr'></ul><sub id='ngYWr'></sub></form><legend id='ngYWr'></legend><bdo id='ngYWr'><pre id='ngYWr'><center id='ngYWr'></center></pre></bdo></b><th id='ngYWr'></th></span></q></dt></tr></i><div id='ngYWr'><tfoot id='ngYWr'></tfoot><dl id='ngYWr'><fieldset id='ngYWr'></fieldset></dl></div>

      <tfoot id='ngYWr'></tfoot>

      1. <legend id='ngYWr'><style id='ngYWr'><dir id='ngYWr'><q id='ngYWr'></q></dir></style></legend>
          <bdo id='ngYWr'></bdo><ul id='ngYWr'></ul>

        <small id='ngYWr'></small><noframes id='ngYWr'>

        使用配置文件的 MailSettings 进行 SMTP 身份验证

        时间:2023-10-05
      2. <i id='8eUoM'><tr id='8eUoM'><dt id='8eUoM'><q id='8eUoM'><span id='8eUoM'><b id='8eUoM'><form id='8eUoM'><ins id='8eUoM'></ins><ul id='8eUoM'></ul><sub id='8eUoM'></sub></form><legend id='8eUoM'></legend><bdo id='8eUoM'><pre id='8eUoM'><center id='8eUoM'></center></pre></bdo></b><th id='8eUoM'></th></span></q></dt></tr></i><div id='8eUoM'><tfoot id='8eUoM'></tfoot><dl id='8eUoM'><fieldset id='8eUoM'></fieldset></dl></div>
        <legend id='8eUoM'><style id='8eUoM'><dir id='8eUoM'><q id='8eUoM'></q></dir></style></legend>

            <bdo id='8eUoM'></bdo><ul id='8eUoM'></ul>
              <tbody id='8eUoM'></tbody>

              <small id='8eUoM'></small><noframes id='8eUoM'>

              1. <tfoot id='8eUoM'></tfoot>
                  本文介绍了使用配置文件的 MailSettings 进行 SMTP 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将 MailSettings 存储在 web.config 中,但是当我发送邮件时,我的 SMTP 服务器报告我需要使用身份验证.我在配置文件中有我的用户名/密码,但仍然失败.

                  I'm storing my MailSettings in a web.config, however when I send the message, my SMTP server reports back that I need to use authentication. I've got my username/password in the config file, but it still fails.

                  如果我执行以下操作,它会起作用,但这似乎是一个额外的步骤.它不应该只是从配置文件中获取并自动使用身份验证吗?

                  It works if I do the following, but it seems like an extra step. Shouldn't it just take it from the config file and use authentication automatically?

                  System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(
                      HttpContext.Current.Request.ApplicationPath);
                  MailSettingsSectionGroup settings =
                      (MailSettingsSectionGroup) config.GetSectionGroup("system.net/mailSettings");
                  
                  SmtpClient client = new SmtpClient();
                  client.Credentials = new NetworkCredential(
                     settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
                  

                  Web.config

                  <system.net>
                      <mailSettings>
                          <smtp from="me@xyz.com" deliveryMethod="Network">
                              <network host="mail.xyz.com" defaultCredentials="true"
                                  userName="me@xyzcom" password="abc123" />
                          </smtp>
                      </mailSettings>
                   </system.net>
                  

                  System.Net.Mail.SmtpException

                  System.Net.Mail.SmtpException

                  超出存储分配.这服务器响应是:请使用 smtp验证.看http://www.myISP.com/support/smtp-authentication.aspx

                  Exceeded storage allocation. The server response was: Please use smtp authentication. See http://www.myISP.com/support/smtp-authentication.aspx

                  超出的存储分配"让我们困惑了很长时间,我们现在忽略它.使用 smtp 身份验证"似乎很重要.

                  The "Exceeded storage allocation" confused us for quite awhile, we now ignore it. It's the "use smtp authentication" that seems to be important.

                  推荐答案

                  编码方式和web.config only方式的区别在于后者有defaultCredentials="true" 设置.那是防止用户名和密码被用于验证,用这种方法.我认为可以通过将其设置为false"(或完全删除它,因为false"是默认值)来解决问题.

                  The difference between the coded approach and the web.config only approach is that the latter has defaultCredentials="true" set. That is preventing the username and password from being used to authenticate, with that approach. I think the problem would be solved by setting that to "false" (or removing it completely, because "false" is the default).

                  这篇关于使用配置文件的 MailSettings 进行 SMTP 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Pop3 到 C# 中的 SMTP 消息自定义转发器 下一篇:SmtpException:客户端或服务器仅配置为具有 ASCII 本地部分的电子邮件地址

                  相关文章

                  <tfoot id='qGg2I'></tfoot>

                  <legend id='qGg2I'><style id='qGg2I'><dir id='qGg2I'><q id='qGg2I'></q></dir></style></legend>

                  <small id='qGg2I'></small><noframes id='qGg2I'>

                    <bdo id='qGg2I'></bdo><ul id='qGg2I'></ul>

                    1. <i id='qGg2I'><tr id='qGg2I'><dt id='qGg2I'><q id='qGg2I'><span id='qGg2I'><b id='qGg2I'><form id='qGg2I'><ins id='qGg2I'></ins><ul id='qGg2I'></ul><sub id='qGg2I'></sub></form><legend id='qGg2I'></legend><bdo id='qGg2I'><pre id='qGg2I'><center id='qGg2I'></center></pre></bdo></b><th id='qGg2I'></th></span></q></dt></tr></i><div id='qGg2I'><tfoot id='qGg2I'></tfoot><dl id='qGg2I'><fieldset id='qGg2I'></fieldset></dl></div>