Simon Bisson
Contributing Writer

Using Azure Communication Services for email

analysis
Jun 29, 20227 mins
APIsDevelopment ToolsMicrosoft Azure

Microsoftโ€™s Azure multichannel communications APIs get support for email.

incoming emails / DNS security / locked server / parked domain
Credit: 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.

Simon Bisson

Author of InfoWorld's Enterprise Microsoft blog, Simon Bisson prefers to think of โ€œcareerโ€ as a verb rather than a noun, having worked in academic and telecoms research, as well as having been the CTO of a startup, running the technical side of UK Online (the first national ISP with content as well as connections), before moving into consultancy and technology strategy. Heโ€™s built plenty of large-scale web applications, designed architectures for multi-terabyte online image stores, implemented B2B information hubs, and come up with next generation mobile network architectures and knowledge management solutions. In between doing all that, heโ€™s been a freelance journalist since the early days of the web and writes about everything from enterprise architecture down to gadgets. He is the author of Azure AI Services at Scale for Cloud, Mobile, and Edge: Building Intelligent Apps with Azure Cognitive Services and Machine Learning.

More from this author