Sunday, July 8, 2012

Email with Attachments via Spring and SendGrid (Part 1)


In this article, we will study how to send emails and include attachments using Spring as our Java framework, SendGrid as our email service, and jQuery-File-Upload as our jQuery plugin. This article is the culmination of my previous articles about email and file upload (see below)

I advise my readers to read those articles first before reading this guide to understand how to send email with SendGrid and how to upload files with jQuery.



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
  • Users can attach multiple files
  • Send email via HTTP instead of SMTP to avoid firewall issues

Here's our Use Case diagram:


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.



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

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

Email with attachments
Notice we can attach multiple files and display their file sizes

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

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

Sample emails
This is the sample email received from Gmail:

This is the sample email received from Yahoo:


In the next section, we will start writing the Java classes, discuss the jQuery-File-Upload process, and the SendGrid API for sending attachments. Click here to proceed.
StumpleUpon DiggIt! Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Email with Attachments via Spring and SendGrid (Part 1) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share


  1. I have read your blog its very attractive and impressive. I like it your blog.

    Spring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training

    spring training in chennai spring hibernate training in chennai

  2. very useful post, thank you so much.

  3. Oh! This article has suggested to me many new ideas. I will embark on doing it. Hope you can continue to contribute your talents in this area. Thank you.
    ludo king

  4. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    core java training in Electronic City

    Hibernate Training in electronic city

    spring training in electronic city

    java j2ee training in electronic city