Getting Started with SendGrid on Windows Azure Mobile Services


Posted on

In this tutorial we will integrate Sendgrid service with the user authentication in Mobile Services. You will be able to send a “Welcome Email” from your app once the authentication is successfully done.

  1. Sign up for Mobile Services
  2. Get Started with Authentication
  3. Sign up for SendGrid
  4. Integrate SendGrid with Azure Mobile Services
  5. Update the authentication process

 

Steps 1 and 2: Sign up for Azure Mobile Services and Get Started with Authentication 

First of all you need to know how to create new Azure mobile app and then how to authenticate users in Windows Azure Mobile Services from a Windows Store app.

Here are the links for these tutorials:

  • Get started with Mobile Services
  • Get started with authentication

 

Step 3 – Sign Up for SendGrid

After you completed these tutorials, getting started with SendGrid on Windows Azure is really easy. The first thing you’ll need is a SendGrid account. You can sign up for it here.

 

Step 4 – Integrate SendGrid with Windows Azure Mobile Services and Download library from repository

Now that your SendGrid account has been created, it’s time to integrate it into your Mobile Services app. We will integrate it with the authentication of users in Windows Azure Mobile Services from a Windows Store app.

You should receive a “Welcome Email” when the authentication is successfully done.

We can send emails using SendGrid service in two ways:

  • using the SendGrid SMTP API
  • using the SendGrid Web API

First, though, you need to use some of the example libraries in order for these samples to work. We suggest you download the SendGrid C# .NET libraries directly from our Github repository.

 

5 – Update the authentication process

In MainPage class

– add new libraries

using System.Net;using System.Net.Mail;using System.Text;using SendGridMail;using SendGridMail.Transport;

 

This code has to be added in the if statement which is checking if login was made the successAdd the following snipped code to the method which is handling the authentication process: “System.Threading.Tasks.Task Authenticate()”

if (result.Status == LiveConnectSessionStatus.Connected)

If you want to send the “Welcome Email” using SendGrid SMTP API, use this code:

var username = “sgrid_username”;var password = “sgrid_password”;var from = “bar@domain.com”;var to = new List<String>{“foo@domain.com”,“raz@domain.com”};// initialize the SMTPAPI example classvar smtpapi = new SMTPAPI(username, password, from, to);// use this section to test out our SMTP examples!

smtpapi.SimpleHTMLEmail();

 

If you want to send the “Welcome Email” using SendGrid Web API, use this code:

var username = “sgrid_username”;var password = “sgrid_password”;var from = “bar@domain.com”;var to = new List<String>{“foo@domain.com”,“raz@domain.com”};// initialize the WEBAPI example classvar restapi = new WEBAPI(username, password, from, to);// use this section to test out our SMTP examples!

restapi.SimpleHTMLEmail();

 

You can find here more details about C# examples using SendGrid Libraries.

 

Next Steps

This concludes a basic integration of SendGrid with Azure Mobile Services. Consider finding out more about the following topics about email and your mobile App:

Integrate with the SendGrid Parse API and have people transform attachments or text on their emails into blog posts or new updates from your app.


Carly Brantz is a veteran in the email deliverability space working to make email simple and easy for developers by regularly writing whitepapers, research briefs and blog posts about email, technology and industry trends.

Carly Brantz on Twitter
Have thoughts on this post?
Chat with us about it on Twitter and Google+