如何通过Azure App Service设置mailSettings-应用程序设置 [英] How to set mailSettings from Azure App Service - Application settings
问题描述
电子邮件服务器的当前设置已签入版本控制。
The current settings for the email server is checked into version control.
<configuration>
<system.net>
<mailSettings>
<smtp deliveryMethod="network">
<network host="..." port="25" password="..." userName="..." />
</smtp>
</mailSettings>
</system.net>
</configuration>
我想从版本控制中删除(至少是密码),以便其他开发人员不能(偶然)通过我们的邮件服务器发送邮件。
I'd like to remove (at least the password) from version control so other developers can't (accidently) send mail over our mail server.
我们正在使用SAAS提供程序作为出站电子邮件,因此,我无法通过设置来限制对该服务器的访问防火墙。唯一的身份验证是使用SAAS提供商提供的用户名和密码。
We're using a SAAS provider for our outbound email, because of this I cannot limit access to this server by setting up a firewall. The only authentication is using username and password provided by the SAAS provider.
是否可以从Azure的应用程序设置刀片中设置mailSettings。这样,我可以从版本控制中删除密码,并且不需要在(自动)部署时手动更新web.config。
Is it possible to have the mailSettings be set from the Application settings blade in Azure. This way I can remove the password from version control and do not need to manually update the web.config upon (automatic) deployment.
推荐答案
<如前所述,您正在使用邮政。在他们的 GitHub 上,我注意到您可以提供一个
As you mentioned you are using Postal. On their GitHub, I notice you can provide a function that creates a SmtpClient.
从此处开始,您可以创建将使用应用程序设置构建的自定义SmtpClient:
Starting from there, you can create a custom SmtpClient that will be built using application settings:
var smtpServerHost = CloudConfigurationManager.GetSetting("SmtpServerHost");
var smtpServerPort = int.Parse(CloudConfigurationManager.GetSetting("SmtpServerPort"));
var smtpServerUserName = CloudConfigurationManager.GetSetting("SmtpServerUserName");
var smtpServerPassword = CloudConfigurationManager.GetSetting("SmtpServerPassword");
var client = new SmtpClient(smtpServerHost, smtpServerPort);
client.Credentials = new NetworkCredential(smtpServerUserName, smtpServerPassword);
通过这种方式,您可以在Azure应用服务的应用程序设置中修改电子邮件设置
This way you'll be able to modify your email settings in the Application settings of your Azure App Service.
这篇关于如何通过Azure App Service设置mailSettings-应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!