grails mail plugin

Posted By : Manish Kumar Narang | 30-Sep-2017

In Web applications, sending email is an imtegral feature. In different frameworks, this task is performed differently. In this blog i will talk about it in reference of Grails framework. In grails framework this functionality is provided by the grails mail plugin. Mail can be sent using the @mailService via the @sendMail method. Here is an example -

def sendEmail(){

    mailService.sendMail {
        to "email","**email**"
        from "email"
        subject "Hi"
        body 'Hi'

 The plugin is easy to configure and provides some very useful features which can be configured in the config.groovy file. 

grails {
    mail {
      host = ""
      port = 465
      username = "email"
      password = "pwd"
      props = ["mail.smtp.auth":"true",

I will discuss three of these features -

  • grails.mail.overrideAddress
  • grails.mail.default.from

The email sending functionality in grails framework can be disabled by setting the parameter grails.mail.disabled to be true.

grails.mail.disabled = true

Grails provide an alternative to the disabling mail functionality and i.e to override the email addresses, in which case, the email addresses (from, to, cc and bcc) will be replaced by the email address provided in the parameter grails.mail.overrideAddress. This functionality can be used both the development and testing environment. One can also have seperate email addresses for different environments. By default the override address is a String. Therefore, one can only add one email address. Though by doing some modifications in the inner workings of the plugin, multiple email addresses can be used. That i shall discuss in some other blog.

The grails.mail.default.from is clear from its name itself. If the override functionality is enabled, the from addresses of the email is replaced by the email address provided in grails.mail.default.from parameter. One should keep in mind that this will happen only if the grails.mail.overrideAddress is provided.

The is similar to grails.mail.default.from parameter. The replacement will happen in the to addresses of the email. 





About Author

Author Image
Manish Kumar Narang

Manish is an experienced Backend Developer with several years of industry experience in the IT field. He possesses a wide range of skills, including expertise in Backend languages like Core Java, J2EE, Hibernate, Spring/Spring Boot, and Python. Manish is also proficient in relational databases such as MySQL, PostgreSQL, and Oracle. He has hands-on experience in API implementations, web services development, testing, and deployments. Manish has contributed to various internal and client projects, including PMO, Catalyst, Communication-Scaffold, Oodles-Dashboard, and Devops Support, delivering significant business value. He is known for his innovative mindset and excellent problem-solving abilities. He keeps himself updated with new technologies by reading about them. He is skilled at collaborating closely with clients to define project scope and requirements, establish project timelines and milestones, and manage expectations. Manish conducts regular project status meetings, ensuring regular updates to clients and stakeholders regarding project progress, risks, and issues. Additionally, he serves as a mentor and coach to junior developers, offering guidance on project management best practices and fostering their skills development.

Request for Proposal

Name is required

Comment is required

Sending message..