我正在使用 RedGate 的部署管理器进行部署。我需要使用 powershell 脚本作为部署的一部分来更改此设置:
<system.net>
<mailSettings>
<smtp from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfbbaabcbb8fbbaabcbbe1aca0a2" rel="noreferrer noopener nofollow">[email protected]</a>">
<network host="mailtrap.io" userName="masked" password="masked" port="2525" enableSsl="false" />
</smtp>
</mailSettings>
</system.net>
为此进行生产:
<system.net>
<mailSettings>
<smtp from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c7c5d0c5c8ddd7d0e4c0c5d0c5c2cdcac7cc8ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>">
<network host="pod51010.outlook.com" userName="someuser" password="somepassword" port="587" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
我的 powershell 经验为零,我不知道从哪里开始。谁能提供一些见解?
最佳答案
我明白了:
#Set the Connection String and the path to web.config (or any config file for that matter)
$webConfigPath = "web.config"
# Get the content of the config file and cast it to XML and save a backup copy labeled .bak followed by the date
$xml = [xml](get-content $webConfigPath)
$root = $xml.get_DocumentElement();
$root."system.net".mailSettings.smtp.network.host = $mailHost
$root."system.net".mailSettings.smtp.network.userName = $mailUsername
$root."system.net".mailSettings.smtp.network.password = $mailPassword
$root."system.net".mailSettings.smtp.network.port = $mailPort
$root."system.net".mailSettings.smtp.network.enableSsl = $mailEnableSSL
# Save it
$xml.Save($webConfigPath)
关于Powershell修改Web.config mailSettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23957949/