Grails email gmail

A great combination!

To send emails using Gmail with a Grails application, you'll need to configure the email plugin and set up your Gmail account. Here's a step-by-step guide:

Step 1: Add the email plugin to your Grails project

In your BuildConfig.groovy file, add the following line:

runtime 'org.grails.plugins:email:3.0.1'

Step 2: Configure the email plugin

Create a Config.groovy file in the root of your project and add the following configuration:

grails {
    mail {
        host = 'smtp.gmail.com'
        port = 587
        username = 'your-gmail-username'
        password = 'your-gmail-password'
        props = ['mail.smtp.auth': 'true', 'mail.smtp.starttls.enable': 'true']
    }
}

Replace your-gmail-username and your-gmail-password with your actual Gmail credentials.

Step 3: Set up your Gmail account for less secure apps

To allow Grails to send emails using your Gmail account, you need to enable "Less secure app access" in your Google Account settings. You can do this by following these steps:

  1. Go to your Google Account settings.
  2. Click on "Security" from the left-hand menu.
  3. Scroll down to the "Less secure app access" section.
  4. Toggle the switch to "On".

Step 4: Send an email using the email plugin

Now you can use the email plugin to send emails from your Grails application. Here's an example:

def sendEmail() {
    def mailService = grailsApplication.mainContext.getBean('mailService')
    mailService.sendMail {
        to '[email protected]'
        subject 'Test email from Grails'
        body 'This is a test email sent from Grails'
    }
}

This code sends an email to [email protected] with the subject "Test email from Grails" and a simple body message.

That's it! With these steps, you should be able to send emails using Gmail with your Grails application.