When it comes to API providers, few are as prominent as SendGrid. A maker of cloud-based software for sending emails, SendGrid offers a service that is used by more than 180,000 customers and sends out a staggering 20 billion emails every month. Some of the biggest names in business, including LinkedIn, Costco, Walmart, and Spotify, use SendGrid to deliver order confirmations, invoices, and other types of emails to their customers, quickly and reliably.

And the Boulder, Colorado, startup has already reeled in $48 million in funding, and it keeps on growing and creating new services. For example, it recently launched a triggered email service called Threads, a behavior-driven, triggered service specifically for marketers. Using Threads, organizations can set up automated emails that are sent based on user activity, so emails could be automatically sent when a customer views a specific webpage or performs a specific action on a mobile app or device.

sendgrid-800x320

Email Integration – Without the Infrastructure 

It’s easy to see the appeal of SendGrid for developers – they can use the platform’s APIs or SMTP relay to send emails without needing their own SMTP server. By taking advantage of the easy integration with the cloud-based SendGrid infrastructure, developers don’t need to build, scale, or maintain in-house email systems. Instead, they can use the growing collection of SendGrid APIs to make sending transactional emails or marketing emails a simple process.

SendGrid simplifies custom integration through its broad range of Web APIs. Developers can use the service’s Web APIs to retrieve statistics, bounces, spam reports, unsubscribes, and other account information. Additionally, the Web APIs allow users to send multiple emails, customize plugins, and access parsed incoming emails with attachments. Some of the service’s specific APIs include:

 

  • Marketing Campaigns API. With this API, developers can manage marketing emails, lists, and identities. Developers can also use the tool to schedule email delivery events.
  • SMTP API. Developers can use this API to tag emails in order to get detailed statistics on each tag and send customized emails in one request via mail merge. Developers can also configure each setting on a per-email basis, by passing a JSON string in the x-smtpapi HTTP parameter.
  • Customer Sub-User API. This API allows developers – and all SendGrid customers – to manage their sub-users and all aspects of sub-user accounts.

 

The IoT Connection

Without a doubt, IoT developers can ease development by taking advantage of SendGrid. For example, the Golgi Programmable Device Cloud Platform integrates easily with SendGrid. Using the SendGrid and Golgi APIs, IoT developers can easily send emails from their embedded devices. One possible use case is status updates: SendGrid emails are an excellent way of adding status update functionality to your embedded devices.

 

Reliable, Scalable, Secure Email Delivery 

In addition to simplifying integration, SendGrid offers a host of benefits:

  • Reliable Delivery. To make sure emails reach the intended recipients, the company employs more than 30 email deliverability experts and compliance agents, dedicated technical account managers to monitor stream quality, and an account provisioning process that allows only high-quality senders on the platform.
  • Scalable Platform. By relying on flexible APIs and a scalable cloud infrastructure, SendGrid helps customers easily scale their email solution while removing infrastructure maintenance costs.
  • Secure, Encrypted Delivery. All email sent via SendGrid uses TLS encryption, as long as the recipients’ mail servers are configured to support it. This protects email from interception or modification.
  • Actionable Analytics. SendGrid offers simple or advanced data analysis on opens, clicks, and subscription tracking, based on user engagement. This real-time data is available through a web-based dashboard and can be customized through the service’s Event or Web APIs.

 

C# Demo: Creating and Sending an Email

As always, the best way to understand a solution like SendGrid is to demo it. In this short example, you can use C# to create and send an email from SendGrid. To make it work, you’ll need .NET 4.5 or above.

Installation. To use SendGrid, you can download the SendGrid C# .NET libraries directly from the Github repository. You could also get the libraries automatically if you have the NuGet package manager installed, at PM>Install-Package SendGrid.

Once you have the SendGrid libraries properly referenced in your project, you can include calls to them in your code. Add the following namespaces to use the library:

using System;
using System.Net; 
using System.Net.Mail; 
using SendGrid;

 

Creating an Email

You can use the new static SendGridMessage constructor to create an email message object. Once you’ve created that message, you can use SendGridMessage properties and methods to set values, including the email sender, email recipient, and subject and body of the email. The example below demonstrates how to create and populate an email object:

 

// Create the email object first, then add the properties.
var myMessage = new SendGridMessage();

// Add the message properties.
myMessage.From = new MailAddress("john@example.com");

// Add multiple addresses to the To field.
List<String> recipients = new List<String>
{
    @"Jeff Smith <jeff@example.com>",
    @"Anna Lidman <anna@example.com>",
    @"Peter Saddow <peter@example.com>"
};

myMessage.AddTo(recipients);
myMessage.Subject = "Testing the SendGrid Library";

//Add the HTML and Text bodies
myMessage.Html = "<p>Hello World!</p>";
myMessage.Text = "Hello World plain text!";

 

Sending an Email

Once you’ve created an email message, you can send it using the SendGrid Web API. To send email, you’ll need to supply SendGrid account credentials or a SendGrid API Key, which is the preferred method. To configure API keys, visithttps://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html

To send a message, use the DeliverAsync method on the Web transport class, which calls the SendGrid Web API. Here’s an example showing how to send a message:

 

// Create the email object first, then add the properties.
SendGridMessage myMessage = new SendGridMessage();
myMessage.AddTo("anna@example.com");
myMessage.From = new MailAddress("john@example.com", "John Smith");
myMessage.Subject = "Testing the SendGrid Library";
myMessage.Text = "Hello World!";

// Create a Web transport, using API Key
var transportWeb = new Web("This string is a SendGrid API key");

// Send the email.
transportWeb.DeliverAsync(myMessage);
// NOTE: If you are developing a Console Application, use the following so that the
//  API call has time to complete 
// transportWeb.DeliverAsync(myMessage).Wait();
ShareShare on Facebook1Share on Google+0Tweet about this on TwitterShare on LinkedIn0
Back to Articles

Leave a Reply