Skip to main content
Continuum Concepts

Add Button Disabled in Email Communication Services MailFrom Addresses? Add it via PowerShell.

Azure Communication Services Email: Adding a Real MailFrom Address

Microsoft now offers Azure Communication Services, which can provide email / SMTP, SMS messaging, chat, and more. I've started using the Email Communication Service as an alternative to Amazon SES, SendGrid, and Twilio.

Provisioning my domain and setting up SPF / DKIM was straight-forward, with the portal UI offering a bit of guidance. I was soon able to send a message from DoNotReply@calories.io. However, when trying to use the portal to add a MailFrom address that pointed to an actual inbox, I found the Add button to be disabled.

I found a question posted to Microsoft Learn: "Add button disabled in Email Communication Services MailFrom addresses" with work-arounds presented by a Microsoft Employee. There's some talk in the thread about increasing your quota, but this is not necessary. The portal UI limits adding MailFrom addresses but the underlying API does not. One user in the thread confirmed that adding the MailFrom via REST worked, but I wanted to try the PowerShell route. It was easy. Here's how to do it:

Prerequisites

If necessary, confirm you have the Azure CLI installed.
Try az upgrade at a PowerShell command prompt to see if it's installed and in your Path. If not, installing it is easy. I used WinGet and ran winget install --exact --id Microsoft.AzureCLI. You'll probably need to close your terminal and open a new one to pick up the updated Path environment variable. Use az login if you need to log in.

Add the communication extension with:

az extension add --name communication

Creating the MailFrom / Sender Username via CLI

My actual command looked like:

az communication email domain sender-username create `
  --domain-name calories.io `
  --email-service-name [my email service name] `
  --username [the part before the @ in the email address inbox] `
  --resource-group [my resource group name] `
  --display-name "[my display name]" `
  --sender-username [again - the part before the @ in the inbox]

It completed in under a second, and after hitting the refresh button in the portal UI, the MailFrom addresses page included the new address in the list.

Sending Email with the SDK

Sending email programmatically with EmailClient's SendAsync() method is simple. You may want to use Azure.WaitUntil.Started and not Azure.WaitUntil.Completed as the latter will cause your code to wait several seconds while your mail operation executes (even with a basic configuration it can take a few to several seconds of processing before your email is actually sent).