我的意思不是从书上读
appSetting
键,然后将它们填充到
System.Net.Mail
物体。我希望参数(例如主机、端口、凭据、发送方等)在运行时自动从配置文件中填充
SmtpClient
是实例化的。
不,你不能。
Application Settings
. (里面有什么设置
覆盖
因为您使用的是
mailSettings
SmpClient
.
您可以创建一个自定义
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);
(受此帖子启发:
How to set mailSettings from Azure App Service - Application settings
)