Monday, June 18, 2012

Email with Spring and SendGrid (Part 1)

Introduction

In this article we will study how to send email with Spring by integrating with SendGrid's email service. Instead of the usual SMTP, we will use HTTP to communicate with SendGrid.


Dependencies


Github

To access the source code, please visit the project's Github repository (click here)

Functional Specs

Let's define our application's requirements:
  • Create a simple form where users can compose and send emails
  • Emails do not need to be persisted in a database
  • Send email via HTTP instead of SMTP to avoid firewall issues

Here's our Use Case diagram:


[User]-(Compose)
[User]-(Send)

In MVC terms, we decompose the application as follows:
  • Model: A simple Map object that conforms with SendGrid's message format
  • View: An HTML-based form where users can compose and send emails
  • Controller: Spring controller that receives the request. The controller delegates actual work to the service layer which eventually executes an HTTP call to send email to SendGrid.

What is SendGrid?

SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time analytics along with flexible API's that make custom integration a breeze.

Source: http://www.sendgrid.com

Why SendGrid?
  1. It's easy to integrate with.
  2. It has a free plan that allows 200 email messages per day.
  3. SendGrid has an HTTP API for sending emails which is very simple to use.

Screenshots

Let's preview how our application will look like after it has been completed. This is also a good way to clarify further our application's specs

This is the entry page where users can compose and send emails.

Compose Email Form

After clicking "Send", the email message is sent. An alert is shown to confirm the action.

Sent alert

When user clicks on "Reset", the contents of the fields are cleared. An alert is shown to confirm the action.

Fields cleared alert

Email Messages
This is the sample email received from Gmail. Notice Gmail is able to show that this email was sent via SendGrid.

Gmail email


email details

This is the sample email received from Yahoo.

Yahoo email

Next

In the next section, we will show how to sign-up with SendGrid's email service. This is required before we can start sending emails. Click here to proceed.
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Email with Spring and SendGrid (Part 1) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share

2 comments: