sean717
sean717

Reputation: 12653

Send email from Azure app service with sender as my domain email

Here is what I want to achieve: I want to send email to clients from a .NET core based web-api hosted on Azure. And I want the email's sender address to be "[email protected]".. which "mydomain.com" is the domain I own from GoDaddy.

I have done some search but surprisingly haven't found any easy to follow tutorials.

Upvotes: 0

Views: 547

Answers (2)

sean717
sean717

Reputation: 12653

I end up using MailKit.

    public void SendMessage(MimeMessage message)
    {
        using (var client = new SmtpClient())
        {
            client.ServerCertificateValidationCallback = (s, c, h, e) => true;

            client.Connect("smtp_host", 465, SecureSocketOptions.SslOnConnect);

            client.Authenticate("admin@mysite", "smtp_password");

            client.Send(message);
            client.Disconnect(true);
        }
    }

Upvotes: 0

rickvdbosch
rickvdbosch

Reputation: 15571

It's really simple to use SendGrid, especially with for instance the Azure Functions SendGrid bindings.

For an approach where you use the SendGrid NuGet package, see How to Send Email Using SendGrid with Azure.

This guide demonstrates how to perform common programming tasks with the SendGrid email service on Azure. The samples are written in C# and supports .NET Standard 1.3. The scenarios covered include constructing email, sending email, adding attachments, and enabling various mail and tracking settings.

Upvotes: 1

Related Questions