Using Azure Communication Services for email

Microsoft’s Azure multichannel communications APIs get support for email.

Using Azure Communication Services for email
Thinkstock / Imaginima / Getty Images

Launched at Ignite in 2020, Azure Communication Services (ACS) is built on top of Teams’ chat and telephony features. It delivers a set of managed communications APIs much like those offered by Twilio and is a quick way of using familiar REST calls to extend your code into new channels. The initial set of features included voice and video chat, as well as SMS and a text chat service.

Although much of the tool is clearly aimed at customer service, both in-app and on the web, adding one-to-one and one-to-many communications to applications can help bring an expert into the loop in field service tools, or direct users to machine learning–driven chatbots using Azure’s natural language processing services. With Teams’ pandemic-tested infrastructure behind its APIs, even though the service is new and still adding features, it’s proven scalable and capable of supporting large consumer-facing applications as well as internal communications.

Adding email to Azure Communication Services

Build 2022 saw Microsoft add a new set of features to the platform, providing new channels and new UI components to simplify building it into your code on non-Microsoft platforms. Expanding the service outside of real-time communications is an interesting move as it changes how users interact with the platform, using email as an asynchronous communication channel that can contain more detail than a simple chat.

Microsoft has been building on Teams and Microsoft 365 to deliver new products and services that bundle together what would have been discrete functionality into new applications. Applications like To Do and Lists are what would have been part of SharePoint. Bookings builds on Teams and Exchange to provide a platform for quickly scheduling meetings and appointments. Those tools work well in many cases, but businesses want to take those core functions and customize them, adding their own features to Microsoft’s services.

Perhaps the best way to think of Azure Communication Services is as a way of extending those Microsoft 365 tools. You might be using Bookings to run appointments for a newly online counseling service, running the sessions outside of Teams using ACS to provide a secure one-to-one channel for video and voice, with a dedicated iOS or Android mobile client built using the new ACS UX libraries, while its new email tools send reminders and private session links to patients.

The email service in ACS is optimized for application-to-person communications, delivering either bulk or transactional emails. The bulk communication option is suitable for sending mass marketing messages and running scheduled mailing lists while automating support for opt-outs. You could use Exchange Online to manage a mailing list, but it’s intended for low-volume operations, and rate limits would prevent sending large numbers of messages. Transactional messages can be dynamically created as part of an application workflow, delivering confirmations to user mailboxes or sending receipts when a purchase has been made.

One key feature in ACS email is support for high-volume sending. Mail is charged per message and by the amount of data transferred, so you will need to keep track of what you send. The costs of $0.00025 per message and $0.00012 per megabyte may seem small, but thousands of messages can quickly add up to hundreds or even thousands of dollars. For more typical use cases, like our appointment reminder example, you’re looking at a couple of dollars a month in usage and data charges, at the most.

Using ACS to send email

Although ACS’s email service uses an Azure domain, in practice, most users will want to use their own domains and addresses to personalize messages. This does require some work: The domain will need to have appropriate DNS records to handle Sender Policy Framework (SPF), Domain Keys Identified Mail (DKIM), Domain-based Message Authentication, Reporting and Conformance (DMARC), and other anti-spam verification protocols. Rember to ensure that you’re set up to receive messages at both the P1 and P2 mail addresses used by the service. P1 is used to set the “mail from” section of the SMTP envelope; P2 is used as the content of the “from,” “reply to,” and “sender” sections. ACS will use these as part of any SMTP interactions with external recipients and email relays and gateways.

Once configured, an Azure administrator can connect the email domain to Azure as an Azure Communication Resource, ready for use by developers. Alternatively, if you prefer, you can use an Azure Managed Domain to automate much of the required configuration.

Once you have an Azure Communication Resource in your resource group, you can connect it to any of the available channels. In the Azure Portal use “connect your email domains” to set up the link, connecting a verified domain to the service. The advantage of this approach is that developers don’t need to know how to set up and connect an email address to the service; all they need to do is write the code to use it. Any network and Azure configuration necessary is the responsibility of the experts in that field.

You can now write code using ACS’s email service. Microsoft currently provides a JavaScript library to simplify this process, with a .NET version also available so you can build and run email apps that run in Azure App Service. You can build and test JavaScript code locally using node.js, installing the library from npm. Your code will use your ACS account’s connection string, which can be found in your Azure environment. The library provides classes and interfaces to manage the key aspects of creating and sending an email message, from managing lists of recipients to adding attachments to a message.

Currently, both JavaScript and .NET have supported libraries. Other languages will need to use REST calls to work with the service. This means they may not have access to all the Sendmail features used by ACS or get message status responses.

To send a message, use the EmailClient object, using it to hold the connection string. You will then create an email message as JSON, adding sender information, content, and a list of recipients. You can then call the library’s send method to send the message. You should treat this as an asynchronous call as it can take some time to send a message to many recipients. Once the message has been sent, get the Message-Id from the response object to get basic message tracking, for example, to check for delivery status. This can help identify messages that need to be resent or that had an incorrect email address.

How to think about ACS and email

Although the service is designed for high-volume email traffic, Microsoft has put some rate limits in place to prevent it from being used to send spam. Initially, the service operates as a developer sandbox, with a limit of 10 messages a minute, 25 an hour, and 100 a day. As you move into production you will need to work with Azure support to raise the limits.

More complex applications can use the service to construct and send messages on demand. To receive and process messages, use the Microsoft Graph APIs to monitor an Exchange Online mailbox set as the “reply to” address in your messages. This will allow you to use tools like Cognitive Services to generate dynamic responses to messages and monitor for bounced or unsubscribe messages. You can programmatically manage mailing lists and notify list owners of problems with their data to ensure that you’re compliant with relevant regulations.

Azure Communication Services is an important part of building custom, end-to-end consumer experiences at scale. Mixing different communication channels in one platform makes sense, allowing our applications to use the most appropriate channel at the right time. We’ve seen how services like Twilio have adopted a multichannel approach as the basis of a CRM and call center strategy, and it’s clear that Microsoft is following in that direction.

For now though, Microsoft’s strategy is clearly built around its own properties: Teams and the Microsoft Graph. In most cases that should suffice, especially if you’re using ACS to extend services such as Microsoft 365’s Bookings or any of its frontline worker tools. However, it would be good to see Microsoft take advantage of APIs and partnerships with additional communication channels, giving your code the ability to reach your customers wherever they are.

Copyright © 2022 IDG Communications, Inc.

How to choose a low-code development platform