I'm working on a Episerver CMS-site that is being moved to Episerver DXC, which is their cloud solution using Azure. On the site the SMTP config in web.config is use. In the test and development environments we dont want to accidently send production mails. In the current test and development environments we use "SpecifiedPickupDirectory" to save the mails on disk instead of sending them. I have searched and tried to find how to config the same in Azure. But I cant figure out how.
Is it possible, or do we have to do it another way?
the current config:
<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>
Best Regards
Niklas
Not Episerver-specific, but if you want them stored on disk for an Azure app service, you could set pickupDirectoryLocation
to something like D:\home\site\wwwroot\App_Data\smtp
.
Config doesn't support app-relative paths, but if you prefer you can set the path programmatically as demonstrated here: How can I save an email instead of sending when using SmtpClient?
TL;DR code sample:
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