How to send emails with Azure Communication Services

DevTools Daily
4 min readAug 13, 2024

--

Introduction

There are multiple email sending services like SendGrid, EmailOctopus, postmark etc.

All of them are great, and usually offer good free tier with roughly $10 per month for 10k emails.

But if you are already using Azure for some reason or if you like to write your own implementations, you can use Azure Communication Service + Azure email service.

The goal of this article is to document what I had to do to set it up, so I can do it again next time. Because it wasn’t as easy as I thought it would be.

Azure Communication Service

Azure Communication Services is a fully managed platform that supports text, voice, video and emails.

Email Communication Service is a part of Azure Communication Services.

How to set it up

Pre requisites

  1. go to Azure portal (https://portal.azure.com/)
  2. assuming you have Azure account, subscription, and resource group.

Create Email Communication Service

First I prefer to start with Email Communication service because it’s most time consuming part.

create new resource

  1. create new resource in Azure portal.
  2. search for “Communication Services” and pick “Email Communication Service”.
  3. pick any descriptive (to yourself) name, and click “Create”.

Add custom domain

  1. open your new resource
  2. click “Setup custom domain”

choose your email domain. I used a subdomain of my domain, like notifications.devtoolsdaily.com

Verify custom domain

  1. verify your domain. You need to add some DNS records to your domain. Azure will give you the values.

2. paste the values in your DNS provider:

Here is an example for Netlify:

And here is Porkbun:

Configurate SPF and DKIM records

These are important for email deliverability.

  1. Azure will tell you which values to put for SPF

2. DKIM
IMPORTANT — add your subdomain

Azure tells you to add

selector1-azurecomm-prod-net._domainkey

but you should add (see subdomain at the end)

selector1-azurecomm-prod-net._domainkey.notifications

as a CNAME record

Create MailFrom address

By default Azure provides with DoNotReply email address. which isn’t even customizable. (at least at the moment of writing on Aug 14 2024)

UI has disabled “Create” button for custom MailFrom address.

but management via azure cli is possible.

az communication email domain sender-username create \
--domain-name notifications.devtoolsdaily.com \
--email-service-name devtoolsdaily-email \
--resource-group <Your group> \
--subscription <Your subscription> \
--display-name "DevToolsDaily team" \
--name "no-reply" \
--username "no-reply"

Now we need to create Communication Service

  1. same as before, create new resource in Azure portal. but now with type “Communication Services”
  2. give it a name, e.g “devtoolsdaily-comms” and click “Create”
  3. go to resource

Connect Domain to Communication service

  1. scroll down to “Email” section in the left menu.
  2. click “Domains”
  3. click “Connect domain”

Send email from Azure portal

  1. open try email
  2. pick correct doman and reply-to address

To be continued…

In Part 2 we will write a simple Node.js script to send emails using Azure Communication Service.

Originally published at https://www.devtoolsdaily.com on August 13, 2024.

--

--