Reputation: 350
We are moving certain background methods that send emails to Azure functions. Our emails are currently built and sent using Postal
Postal uses .NET Framework’s built-in SmtpClient, which has connection details defined in a web.config file for our MVC web app, which doesn't exist in an Azure Function.
Is there a way to use Postal in an Azure Function?
Upvotes: 0
Views: 68
Reputation: 32693
If you look at the source code of the project on GitHub, you'll see that Postal's EmailServer takes in a Func. If you don't provide it, it creates an SmtpClient by executing the new SmtpClient()
constructor, which pulls configuration in from the .config file. So if you want avoid using a .config file to get the settings, pass in a Func.
public SmtpClient CreateMySmtpClient()
{
var client = new SmtpClient("mysmtpserver.com");
// set credentials, timeouts etc
return client;
}
public void SomeOtherMethod()
{
var emailService = new EmailService(ViewEngines.Engines, CreateMySmtpClient);
dynamic email = new Email("Test");
email.Message = "Hello, world!";
emailService.Send(email);
}
Upvotes: 1