Introduction
While working on my current project, we needed to generate an email attachment and send it to an internal group at the company. We had a fixed deadline and had no time to wait for external parties. The company uses Azure, and we started looking for a service to utilize.
This blog post examines the Azure Communication Service for email sending, including when to choose it and some lessons learned during its configuration.
Azure Communication Service
Azure Communication Service (ACS) is a cloud-based communication platform provided by Microsoft Azure, enabling developers to add real-time communication features to their applications. Among its many capabilities, it offers email communication services that allow businesses to send transactional emails programmatically. See https://learn.microsoft.com/en-us/azure/communication-services/overview for more information about the service.
Our use case
As briefly mentioned in the introduction, we needed to send an email to an internal group at the company. They required a monthly summary of tax savings for internal users. In other words, low volume of emails. Very low. We were sure that the Azure Communication Service could handle one email per month. Additionally, we did not care about the email address.
We wanted to test how fast we could move when having complete control over our infrastructure and removing external dependencies for DevOps teams, for example. We decided to timebox testing out the Azure service.
Configuration and setup
The first gotcha when using the Azure Communication Service was the connection between the Azure Communication Service and the Azure Communication Services Email. We use Terraform, and there, the relationship between the two became apparent. Long story short, first, we create an instance of the Azure Communication Service, which provides access keys that we use in our code. However, to send out emails, we also needed an Azure Communication Services email and link it to the Communication Service. An excerpt from the Terraform code:
resource "azurerm_communication_service" "main" {
name = "acs-flint${var.name}-${var.environment}"
resource_group_name = var.resource_group_name
data_location = "Norway"
tags = var.tags
}
resource "azurerm_email_communication_service" "main" {
name = "acse-${var.name}-${var.environment}"
resource_group_name = var.resource_group_name
data_location = "Norway"
tags = var.tags
}
resource "azurerm_email_communication_service_domain" "main" {
name = "AzureManagedDomain"
email_service_id = azurerm_email_communication_service.main.id
domain_management = "AzureManaged"
}
resource "azurerm_communication_service_email_domain_association" "main" {
communication_service_id = azurerm_communication_service.main.id
email_service_domain_id = azurerm_email_communication_service_domain.main.id
}
I like this plugin design. Since we do not need the SMS part of Azure Communication Services, we could ignore it. Reducing the amount of infrastructure.
The Azure Communication Email Service enables you to easily test email sending. It even has a dedicated UI for it. In this example, we created an AzureManaged email domain name, which results in a FromEmailAddress like: DoNotReply@{guid}.azurecomm.net. It was automatically configured for us. It is possible to add your own verified domain.
Alternatives
One of my colleagues brought to our attention a limitation in the Azure Communication Email Service. If you are in a scenario where you need to send a large number of emails, contact external customers, or rely on your emails not being filtered into spam, then consider studying your domain reputation or even sending a request to Microsoft Azure. Developers can find more information in the documentation.
I have previously used SendGrid, which I now see has been acquired by Twilio. Somehow, they manage to keep your emails out of the spam folder. Additionally, it supports sending a large amount of emails.
Conclusion
The Azure Communication Service offers a straightforward and efficient method for sending emails directly from your Azure infrastructure. For our specific use case, with low-volume internal emails, it proved to be the perfect solution. The service is easy to set up using infrastructure as code, and the plugin architecture allows you only to implement the features you need.
However, it's important to note that for scenarios requiring high-volume email sending or where email deliverability is critical, you might want to consider alternatives like SendGrid. The Azure Communication Service has certain limitations regarding email quotas and domain reputation that you need to consider when selecting this service.