Sending email through amazon mail service in Grails

Posted By : Kundan Ray Akela | 28-Jun-2015

Sending email through amazon mail service in Grails

In this blog , I am going to share information about how to configure and send email through Amazon simple email sevice.

A short details about Amzon SES.
We need to send email like business messages of transactional messages in almost every application and we cannot ignore the complexity and cost.Managing our sending email properly we must need to deal with some challeges like infrastructure(server management,network configuration, and IP address reputation).

Amazon SES properly handle these challenges.We can use SMTP or API call to get Amzon high quality email services.

Steps to configure email:

1.Obviously , we need to signup on Amazon ( 

2.We need to verify that you own the domain or address from which you’ll be sending email.

3.You can increase the limit of sending email.

4.We can use either SMTP or the Amazon SES API to queue an email message for delivery.

5.Amazon SES provides useful statistics about our sending activities.

6.All we need to do Amazon SES console.

Sending in grails:

Build Config

compile 'com.amazonaws:aws-java-sdk:1.9.37'

In config


Here is a simple service that sends email.

package com.makzy.service
import com.makzy.domain.User

class MailService {
    def grailsApplication

    /** The transactional. */
    static transactional = false

    /** The amazon web service. */
    def amazonWebService

    /** The groovy page renderer. */
    def groovyPageRenderer

     * Sets the async mail.
     * @param model - domain object
     * @param template - template used for mail
     * @param from - from address
     * @param destination - array of addresses mail is sent to
     * @param subject - mail subject
     * @return the java.lang. object
    public def sendMail(subject, template, model, destination) {

        def from =
        def output = groovyPageRenderer.render view: '/emailtemplates/' + template, model: [data: model]
        Body body = new Body().withHtml(new Content(output.toString()))
        Message message = new Message(new Content(subject), body)
        def result = SendEmailRequest(from.toString(), new Destination([destination]), message))
	println result
	return result

Here emailtemplate is a html page containing content of the mail.

About Author

Author Image
Kundan Ray Akela

Kundan has good programming and problem-solving skills.He is very good in explaining the ideas clearly and make the proper system design as well as plan.His hobbies are to play cricket and travel.

Request for Proposal

Name is required

Comment is required

Sending message..