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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Shakil Pathan
Shakil is an experienced Groovy and Grails developer . He has also worked extensively on developing STB applications using NetGem .