Home > Twilio SendGrid: The Cloud SMTP Provider
Guillaume David
22 June 2022
Lire cet article en Français
3 min

Twilio SendGrid: The Cloud SMTP Provider

We often need to send business (marketing, consumer journey, etc.) and technical (alert notifications) emails within modern integration architectures. Using an on-premise SMTP server is the traditional method; however, cloud solutions now make it easier and faster to meet these sometimes complex needs. For this reason, Microsoft has included the Twilio SendGrid component as an SMTP provider. Let’s look at the benefits of this solution over a conventional SMTP server and the various ways to connect to it.

 

What is Twilio SendGrid?

Twilio SendGrid is a cloud SMTP provider that acts as a marketing and technical email delivery engine. Added to Azure in December 2012, this solution manages the technical aspects of email delivery, such as

  • infrastructure scaling
  • internet service provider (ISP) awareness
  • monitoring
  • real-time analysis

SendGrid started as a simple SMTP provider in 2009. It partnered with Twilio in 2012 to add SMS messaging and push notifications. Twilio went on to buy it out for 2 billion dollars in 2018. The service was then renamed Twilio SendGrid.

 

The Benefits of Twilio SendGrid Over an SMTP Server

Twilio SendGrid’s key advantages over a conventional SMTP server are largely cloud-related: scalability, high availability, and a faster time-to-market without managing the infrastructure of an SMTP server.

 

Scalability

When you build the component, you have the option of several different consumption plans:

  • Free Up to 100 emails/day to try out the solution.
  • Multiple Essentials plans that let you send up to 100,000 emails per month.
  • Multiple Pro plans that let you send up to 2.5 million emails per month. These plans also include a dedicated IP address and sub-user management.

Note:  You can scale your consumption plan up or down during use to match your actual platform consumption without any service disruption.

 

High Availability

Twilio SendGrid is based on a hybrid architecture that includes multiple data centers, global inbound edge locations, and failover policies that guarantee platform availability.

Note: An availability SLA of 99.99% has been announced.

 

Twilio SendGrid also includes monitoring tools in its administration portal, including a comprehensive dashboard showing the email activity handled by the solution. This dashboard contains additional KPIs in the “Stats” section, such as recipient geolocation, etc.

It also provides an Event system that can be integrated easily into the business processes. There are two event types:

  • Delivery events indicating the delivery status for emails to the recipient
  • Engagement events indicating how the recipient interacts with the email

 

Twilio sendgrid Dashboard monitoring
Monitoring dashboard overview

 

A detailed status for the email workflow can be seen in the “Activity” section.

Twilio sendgrid workflow mail

 

In summary, Twilio SendGrid is a quick and easy way to incorporate a centralized and monitored email delivery engine into business and alert processes to meet functional and technical needs.

 

How to Use Twilio SendGrid?

To address all integration issues, Twilio SendGrid provides two ways of sending emails:

  • via SMTP API
  • via API

Twilio Sendgrid Cloud tracking display

 

Requirements for Sending an Email via Twilio SendGrid

Regardless of which method you choose, there are two requirements before you can send an email.

First, an administrator must configure an API key in the console to enable authentication.

In Settings > API keys:

Twilio SendGrid creat API key

 

This key must have “mail” permissions at a minimum.

Twilio SendGrid key

 

⚠️Note: Remember to keep the key safe because you won’t be able to retrieve it later.

Key created in Twilio SendGrid

 

The second requirement is to set up sender authentication, so SendGrid can send emails in your name. There are two ways to do this:

  • Domain Authentication (preferred for production)
  • Single Sender Verification

 

This can be configured in Settings > Sender Authentication:

twilio Sendgrid sender settings

 

Here are the links to the SendGrid documentation on configuration using the two methods if you need more information:

 

Sending Emails via SMTP

TwilioSendGrid can use SendGrid’s SMTP API to send emails:

 

  • Set the server host to “sendgrid.net” in the mail client or app (this setting is sometimes called external SMTP server or SMTP relay)
  • Specify the user name in the apikey string (this is the exact “apikey” string and not the API key itself)
  • Configure the password in the generated API key (see above for how to generate the API key)
  • The port can be configured according to your chosen connection method:
    • For SSL connections: use port 465
    • For TLS or decrypted connections: use ports 25, 2525, or 587 (recommended)

 

⚠️ Note:

Limitations of the SMTP method:

  • Ability to send up to 5000 messages per SMTP connection
  • 10,000 simultaneous connections can be opened from a single server

 

Sending Emails via API

Twilio SendGrid provides a POST “/mail/send” REST API that allows you to send emails via the web API.

Configure the request as follows:

Twilio sendgrid API

  • Body:
    • attachments: a table listing the attachments for an email
    • content: the content of the email in HTML format
    • from: information about the sender (email address, name)
    • personalizations: a table containing information about the email recipients in the To and copy fields
    • subject: subject of the email

 

Note: the email address used must have been verified first via one of the aforementioned methods.

Twilio SendGrid exemple de payload d'API
Example API payload

 

 

Note: the request is checked before the mail is sent. If there are errors, SendGrid will identify and return as many problems as possible for each request.

 

Note: Using API also has limitations:

  • The total email size must be less than 30 MB, including attachments.
  • The total number of recipients must not exceed 1000. This includes all recipients defined in the “to,” “cc,” and “bcc” parameters for every object in the “personalizations” table
  • The total length of any “custom arguments” must be less than 10,000 bytes
  • Unicode encoding is not supported for the “from” field
  • The “name”, “cc.name” and “bcc.name” customizations cannot include the characters “;” or “,”

 

The main things to remember:

Microsoft has integrated the Twilio SendGrid service into its portfolio to meet the rising need among companies to send emails as part of their varied professional requirements. This enables businesses to consolidate email sending and monitoring into a single platform. Using the API interface is preferred within modern integration processes. The SMTP method is recommended for legacy processes that do not support API communication.

This posts should interest you
Comments
Leave a Reply

Receive the best of Cloud, DevOps and IT news.
Receive the best of Cloud, DevOps and IT news.