When hosting a WordPress site as an App Services site on Azure you will find email will not work. Microsoft does not provide the ability to send emails directly from the App Services site, you need to use an external relay service such as SendGrid instead
Table of Contents
- Setting up SendGrid on Azure
- Setting up a SendGrid API Key
- Want to use an Azure Front Door?
- Want a fast WordPress theme or looking to improve your Ad revenue?
Setting up SendGrid on Azure
Within your Azure subscription, create a new resource searching for and selecting SendGrid
As when creating an Azure resource complete the wizard defining your Resource Group and the other properties required or SendGrid. I won’t go into a lot of details here on setting up SendGrid as Microsoft had a great bit of documentation already.
Setting up a SendGrid API Key
Within your SendGrid resource select Overview => Manage
Next on left navigation select Settings => API Keys
In the top right click Create API Key
Give your API a name and if you are only sending an email using this API key you can just set the permission as Restricted Access and the only permission that is needed is Mail Send
Press Create & View at the bottom
Make sure you take a copy of the new API key as you won’t get to see it again in SendGrid!
As you would imagine with WordPress there are a few ways to get mails sending via SendGrid. I personally like to use a free plugin called “Post SMTP Mailer/Email Log”
Within your WordPress admin console search for, install, and active the “Post SMTP Mailer/Email Log” plugin.
Under Plugins select Settings for the newly install “Post SMTP” plugin
Click “Start the Wizard”
Set your from address as required and click Next
Set the “Outgoing Mail Server Hostname” as smtp.sendgrid.net and press Next
Select SendGrid API and click Next
Paste in your API Key created earlier in SendGrid. If you no longer have the key you will need to delete and create a new one. Click Next
On “6. Notifications” just press Next and then Finish
Finally try sending a test mail with the “Send a Test Email” wizard
You may want to add SendGrid into your domains SPF records i.e. v=spf1 include:sendgrid.net ~all. For more information on SPF, DKIM and DMARC check out this post SPF, DKIM and DMARC Confused?
I personally had an issue with my email filtering solution blocking the emails as a spoofing attempt so I had to add a bypass rule
Want to use an Azure Front Door?
If you want to host your WordPress site behind an Azure Front Door take a look at this post WordPress & Azure Front Door Too Many Redirects