【问题标题】:SMTP SpecifiedPickupDirectory in Azure?Azure 中的 SMTP SpecifiedPickupDirectory?
【发布时间】:2020-02-13 06:43:10
【问题描述】:

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

有可能吗,还是我们必须以其他方式做到这一点?

当前配置:

 <system.net>
  <mailSettings>
    <smtp from="no-reply@domain.com" deliveryMethod="SpecifiedPickupDirectory" >
      <specifiedPickupDirectory pickupDirectoryLocation="C:\inetpub\mailroot\Pickup" />
      <network host="smtp.domain.com" port="25" defaultCredentials="true" />
    </smtp>
  </mailSettings>
</system.net>

最好的问候

尼克拉斯

【问题讨论】:

    标签: asp.net asp.net-mvc azure smtpclient episerver


    【解决方案1】:

    不是 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
    

    【讨论】:

    • 谢谢,成功了!我不确定如何在云中指定目录位置。但是您的解决方案“D:\home\site\wwroot\App_data\smtp”有效!
    猜你喜欢
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 2016-02-26
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多