Monthly Archives: March 2010

Sending email from Grails using Gmail

There is already a well-written article about how to send email using Grails hosted on grails.org. As it is already stated there, you need to add the JavaMail and JAF JAR files to your Grails app’s lib directory to be able to send email from your Grails app. However, instead of manually downloading these files and placing them under the lib directory, you can simply uncomment the following two lines of the BuildConfig.groovy file:

and add the appropriate dependencies under the dependencies part of the BuildConfig.groovy:

Then the first time you run your application, Grails will automatically download the specified version of these JAR files for you and places them on the classpath of your application thereafter.

The tricky part is how to use Gmail as the SMTP provider. To do so, you need to configure the mailSender Spring bean as follows:

You can learn more about these JavaMail configuration properties here. In case your SMTP provider does not require encryption, the configuration will be much simpler:

You can download the completed application which lets you compose and send plain text emails from here.

Software Projects, Explained

I had originally posted this about 7 years ago on my old blog at JRoller. Looks like some of the files I had uploaded to JRoller have been deleted since then, and as a result the image is not showing up there anymore, but I was able to find another copy of this image using Google’s image search. Credit is due to the original author who is unknown to me.

Software Projects, Explained

Software Projects, Explained