gpt4 book ai didi

asp.net - Azure 中的 SMTP 指定取件目录?

转载 作者:行者123 更新时间:2023-12-03 05:41:26 25 4
gpt4 key购买 nike

我正在开发一个 Episerver CMS 站点,该站点正在迁移到 Episerver DXC,这是他们使用 Azure 的云解决方案。在网站上,使用 web.config 中的 SMTP 配置。在测试和开发环境中,我们不想意外发送生产邮件。在当前的测试和开发环境中,我们使用“SpecifiedPickupDirectory”将邮件保存在磁盘上而不是发送它们。我已经搜索并尝试找到如何在 Azure 中进行相同的配置。但我不知道怎么办。

这可能吗,还是我们必须采取其他方式?

当前配置:

 <system.net>
<mailSettings>
<smtp from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b757436697e6b77625b7f74767a727535787476" rel="noreferrer noopener nofollow">[email protected]</a>" deliveryMethod="SpecifiedPickupDirectory" >
<specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\Pickup" />
<network host="smtp.domain.com" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>

最诚挚的问候

尼克拉斯

最佳答案

不是 Episerver 特定的,但如果您希望将它们存储在 Azure 应用服务的磁盘上,您可以将 pickupDirectoryLocation 设置为类似 D:\home\site\wwwroot\App_Data\smtp.

Config 不支持应用程序相对路径,但如果您愿意,可以通过编程方式设置路径,如下所示:How can I save an email instead of sending when using SmtpClient?

TL;DR 代码示例:

var client = new SmtpClient();    

if (client.DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory && client.PickupDirectoryLocation.StartsWith("~"))
{
string root = AppDomain.CurrentDomain.BaseDirectory;
string pickupRoot = client.PickupDirectoryLocation.Replace("~/", root);
pickupRoot = pickupRoot.Replace("/",@"\");
client.PickupDirectoryLocation = pickupRoot;
}

// TODO Send e-mail using client

关于asp.net - Azure 中的 SMTP 指定取件目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58414075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com