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

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

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

      在 web.config 中设置多个 SMTP 设置?

      时间:2023-10-06
      <tfoot id='WW1Eg'></tfoot>
        <bdo id='WW1Eg'></bdo><ul id='WW1Eg'></ul>
        <legend id='WW1Eg'><style id='WW1Eg'><dir id='WW1Eg'><q id='WW1Eg'></q></dir></style></legend>

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

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

                <tbody id='WW1Eg'></tbody>

                本文介绍了在 web.config 中设置多个 SMTP 设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在构建一个应用程序,该应用程序需要在发送电子邮件时以动态/编程方式了解并使用不同的 SMTP 设置.

                I am building an app that needs to dynamically/programatically know of and use different SMTP settings when sending email.

                我习惯于使用 system.net/mailSettings 方法,但据我了解,它一次只允许一个 SMTP 连接定义,由 SmtpClient() 使用.

                I'm used to using the system.net/mailSettings approach, but as I understand it, that only allows one SMTP connection definition at a time, used by SmtpClient().

                但是,我需要更多类似 connectionStrings 的方法,我可以在其中根据键/名称提取一组设置.

                However, I need more of a connectionStrings-like approach, where I can pull a set of settings based on a key/name.

                有什么建议吗?我愿意跳过传统的 SmtpClient/mailSettings 方法,我认为必须...

                Any recommendations? I'm open to skipping the tradintional SmtpClient/mailSettings approach, and I think will have to...

                推荐答案

                我需要在 web.config 中有不同的 smtp 配置,具体取决于环境:dev、staging 和 production.

                I needed to have different smtp configurations in the web.config depending on the environment: dev, staging and production.

                这是我最终使用的:

                在 web.config 中:

                In web.config:

                <configuration>
                  <configSections>
                    <sectionGroup name="mailSettings">
                      <section name="smtp_1" type="System.Net.Configuration.SmtpSection"/>
                      <section name="smtp_2" type="System.Net.Configuration.SmtpSection"/>
                      <section name="smtp_3" type="System.Net.Configuration.SmtpSection"/>
                    </sectionGroup>
                  </configSections>
                  <mailSettings>
                    <smtp_1 deliveryMethod="Network" from="mail1@temp.uri">
                      <network host="..." defaultCredentials="false"/>
                    </smtp_1>
                    <smtp_2 deliveryMethod="Network" from="mail2@temp.uri">
                      <network host="1..." defaultCredentials="false"/>
                    </smtp_2>
                    <smtp_3 deliveryMethod="Network" from="mail3@temp.uri">
                      <network host="..." defaultCredentials="false"/>
                    </smtp_3>
                  </mailSettings>
                </configuration>
                

                然后在代码中:

                return (SmtpSection)ConfigurationManager.GetSection("mailSettings/smtp_1");
                return (SmtpSection)ConfigurationManager.GetSection("mailSettings/smtp_2");
                return (SmtpSection)ConfigurationManager.GetSection("mailSettings/smtp_3");
                

                这篇关于在 web.config 中设置多个 SMTP 设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:测试 SMTP 服务器正在通过 C# 运行 下一篇:如何通过 Gmail 使用 C# 发送电子邮件

                相关文章

              1. <legend id='8KYBP'><style id='8KYBP'><dir id='8KYBP'><q id='8KYBP'></q></dir></style></legend>

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

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

                      <bdo id='8KYBP'></bdo><ul id='8KYBP'></ul>
                    <tfoot id='8KYBP'></tfoot>