Using Amazon Simple Email Service in Grails

Posted By : Shakil Pathan | 29-Sep-2014

Hi,

In this blog I am going to explain you about how to use AWS Simple Email Service in grails app for sending mails.

Amazon Simple E-mail Service (SES for now), it is a Sending E-mail Service provided by amazon, with a real low cost for users. The plugin interacts with it, so you can send e-mails using SES infrastructure without extra code in your app.

Unfortunately, SES does not provide a simple SMTP server address to connect and use, otherwise we could just configure the Grails Mail Plugin to use it. Instead of this, AWS provides a http web service for it.

Dependency:

compile ":aws:1.7.5.0"

After that you have to configure your grails config(config.groovy) file to use this plugin:

 

grails {
	plugin {
	   aws {
		  credentials {
			 accessKey = "access_key"
			 secretKey = "secret_key"
		  }
		  
		  ses {
			  enabled = true
//			  catchall = "[email protected]"
			  from = "[email protected]"
			  region = "EU_WEST_1"  //optional, defaults to US_EAST_1
		   }
	   }
	}
 }
 

After configuration you have to write this small code to send email:

 

 

def mailId = sesMail {
	from "[email protected]"
	to "[email protected]"
	subject "test plain text mail"
	body "this is the e-mail content, sent at: (${new Date().format('dd/MM/yyyy HH:mm')})"
}
 

The sesMail returns an unique identifier for this e-mail at Amazon infrastructure. This id can be used in future if you want, you'll be able to retrieve if this email was delivered correctly, or if it was spammed or bounced.

Thanks

Shakil

About Author

Author Image
Shakil Pathan

Shakil is an experienced Groovy and Grails developer . He has also worked extensively on developing STB applications using NetGem .

Request for Proposal

Name is required

Comment is required

Sending message..