How To Add SendGrid to Your Cloud Application Development Toolbox

By Tim Archer| June 21, 2017

When moving your custom applications to the cloud, you’ll need an SMTP server to ensure your outbound emails don’t get stuck in spam. While there are several cloud-based SMTP providers on the market, SendGrid is a popular choice – and for good reason. Not only is it already part of your Azure subscription, but the advanced platform is also easily accessible and capable of sending both transactional and bulk email. And developers will be especially happy to know that SendGrid only takes a few minutes to set up!

Setup SendGrid with your Azure subscription in order to:

  • Have an SMTP server readily available within minutes by provisioning the SendGrid service through the Azure portal.
  • Have an advanced platform capable of sending bulk email for purposes such as marketing newsletters.
  • To be able to identify email delivery statistics, such as if the email was delivered and who opened the email.

How to Set Up and Utilize SendGrid:

  1. Add the SendGrid resource to your Azure subscription: Log in to your Azure portal and add a new resource. Search for “SendGrid Email Delivery.” Then, click on the SendGrid Email Delivery service and press “Create.”
  2. Configure the SendGrid details: You will then be prompted for the information about your new service. Simply give it a name, password, resource group, and select the appropriate pricing tier. Press “Create.”
  3. Let your resource deploy: It may take up to a few minutes for Azure to provision your new SendGrid service. Wait a few minutes, or until the Azure portal says the operation is complete, and then open your resource group and refresh to see your new service.
  4. Get your SendGrid properties: Open the SendGrid resource. From there, you’ll find a couple key sections that you’ll need to know about: 1) Press the manage button to be taken to the SendGrid website where you can see all of your mail delivery statistics and information. 2)Go to the “Configurations” section in order to get the SMTP server, username, and password to use within your application.
  5. Begin using SendGrid: It’s that easy! You’re ready to send emails from your system as you normally would with any other SMTP server. For example, you can point a Wordpress server at the SendGrid service so it emails through it. Or, in the case of many of our clients, begin to utilize SendGrid through your custom C# code to deliver emails.

Here is some sample C# code showing you how to send emails through SendGrid. Simply add the mail server info into your web.config or app.config files as follows:

<smtp deliveryMethod="Network" from="">
<network host="" defaultCredentials="false" port="587" userName="USERNAME" password="PASSWORD" />

Then use code such as the following to create and send:

        public void SendMyEmail(string messageFromAddress, string messageToAddress, string messageSubject, string messageBody, bool messageBodyHtml)
var message = new MailMessage(messageFromAddress, messageToAddress);
message.Subject = messageSubject;
message.Body = messageBody;
message.IsBodyHtml = messageBodyHtml;
using (var mailClient = new SmtpClient())
mailClient.Send (_message);


Tech Insights Report