How do you access .NET Framework default SMTP service in Azure Functions? Using Postal in Azure Function

you'll learn how to send emails with C# .NET using Azure Functions and SendGrid bindings. If you also want to send SMS, ...

How do you access .NET Framework default SMTP service in Azure Functions? Using Postal in Azure Function

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);
}

Click Here to Visit

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0