Blog Post

Azure Communication Services Blog
3 MIN READ

Send emails via SMTP relay with Azure Communication Services

qureshiaquib's avatar
qureshiaquib
Icon for Microsoft rankMicrosoft
Jun 25, 2024

We’ve come across multiple cases where customers want to send emails from applications migrated to Azure through some kind of SMTP service. Though we’ve seen customers opting for O365 for SMTP relay, this can create issues due to throttling limitations in Office Service. Also, managing mailbox and license assignment on Office 365 console is a different story; customers would want to have seamless SMTP relay service experience from single console on Azure.

In scenarios where you don’t want to modify code and just change the pointing of your SMTP server to Azure, you can now use SMTP relay built into Azure Communication Services' Email.

Azure Communication Services supports different types of notifications, and this blog post offers simple step by step instructions for how you can quickly test and then migrate from other services you’re using to native to Azure for better operational experience and support.

Create Azure Communication Services Resource


First step you’ll need to do is to create a Communication Services resource from the Azure portal. This is a parent service which has multiple notification services inside it (Chat, SMS, Email, etc). Email is one of them.


Create an Email resource

 

Add a custom domain

 

Azure Communication Services Email will provide a default domain that looks like this “GUID.azurecomm.net” and allows for a limited volume of email, so if you need more volume limits, we recommend creating a custom domain. Once you add a custom domain, the UI provides you with a TXT file which you’ll need to create in your Name server. This would take 15 minutes to verify the domain




Once the domain is verified, create SPF and DKIM records so that your email doesn’t land in junk and ownership is maintained.





Once all the records are created the screen would look like this, please ignore the Azure managed domain. You can only have custom domain in the account and doesn’t have to add Azure domain explicitly.

 

 

Attach custom domain 

 

Once the custom email domain is validated, we’ll need to attach the Email service to the Azure Communication Services resource. 

 

 

Create and assign custom RBAC Role for Authentication

 

We’ll be using 587 port to send email which is authenticated SMTP. For authentication we have Entra ID authentication. Create a service principal by going to Entra ID – App registration page. Register the app and create a client secret. Note down Client ID, Tenant ID and Secret value. This will be used in next stage for authentication. We’ll need to create a custom RBAC role which has permission to send email. We’ll clone reader role.

 

 

And we’ll be adding two actions which is present in Azure Communication service resource provider.

 

 

Once the Role is created we’ll need to assign this to service principal

 

Test SMTP Relay via Powershell

 

That’s all, now you’ll need to find out the sender email. Which is default DoNotReply@domain.com

 

 

Spoiler
Note: As you can see in the screenshot Add button is greyed out. You can add custom sender email by sending couple of emails from the default email address and then raising support case. support engineer can help you change the tier to higher which will allow you to add more custom email address.

 

You’ll need credentials to authenticate to the service.

 

  • Username is < Azure Communication Services Resource name>. < Entra Application ID>. < Entra Tenant ID>
  • Password is the client secret which you’ve generated.
  • Port that we’ll need to use is 587
  • SMTP server address is smtp.azurecomm.net

 

Now you can use any third party application to send email via the above parameters. To showcase we can use PowerShell with the same parameters to send emails.

 

 

Conclusion: I trust this guide helps you in configuring SMTP relay and send emails from your custom application without any change to the application/code.

 

Happy Learning!

 

 

Updated Jul 26, 2024
Version 3.0
  • dave725's avatar
    dave725
    Copper Contributor

    I'm attempting to use this method to create a username and password to send messages from an older copier, since the ability to use SMTP AUTH is gone with Security Defaults, and the service as a whole is done in 2025. The obvious issue I saw, and have run into, is that the username and password lengths are insanely long for an older device to accept. Is there a method that I can use to reduce the length of these two fields? Otherwise, this solution is no good for users of old machines. Thanks for the excellent tutorial!

    (Password is 32 max, Username is 64 max on my Canon Copier/Printer/Fax)

    • AquibQureshi's avatar
      AquibQureshi
      Brass Contributor

      Hi Dave, can you please check below post. There will be a private preview soon to fix this. 

      https://techcommunity.microsoft.com/blog/exchange/exchange-online-to-retire-basic-auth-for-client-submission-smtp-auth/4114750/replies/4292292

  • robykurian's avatar
    robykurian
    Copper Contributor

    what type of certificate we need to use when we are sending emails? For example, what type of certificate we need to get the connectivity to Azure communication service to send emails? 

     

     

  • sadlergeorge this is encrypted and also authenticated via username and password. The PowerShell method is just an example btw you'll be using application.

  • imran's avatar
    imran
    Copper Contributor

    qureshiaquib  thanks for sharing! It's awesome. On March 7, 2023, I raised a concern about using the SMTP relay service of Azure email communication service, while the service was under preview. Thanks, Microsoft for publishing this.

  • Kexy Biscuit's avatar
    Kexy Biscuit
    Brass Contributor

    It seems that currently ECS requires itself to be the only SPF record? Which disallowing us to add ECS to our main domain.

  • JanSD  Thanks for reaching out.  For sending limits you need to setup and start sending emails with your custom domain and request for your throughput needs. Based on your reputation the limits will be approved. 

  • JanSD's avatar
    JanSD
    Copper Contributor

    Thanks for this, very interesting.  Can you tell me what the sending limits are or at what rate throttling will happen with an smtp relay setup like this?

     

    Thanks!