Monday, May 28, 2012

Setting up Grails email using Amazon Web Services (AWS) Simple Email Service (SES)

So, I was having some issues with the limitations on using Zoho, and decided to branch out and try making things work with AWS SES. I found this great tutorial on how to use SES without installing any plugins other than the standard Mail plugin. While the tutorial was well-written, it didn't work. I got errors indicating that Grails didn't know how to process the following config.groovy line:

grails.mail.protocol = 'aws'

So, I decided to try a tutorial that used the AWS plugin. I finally got this working, but had to learn by trial-and-error that there was a missing dependency on the AWS SDK for Java. I added the files aws-java-sdk-1.3.2.jar, httpclient-4.1.1.jar, and httpcore-4.1.jar from that SDK plus the jets3t-0.9.0.jar file from the JetS3T SDK, and then things worked.

I plan to use this in many future projects, so I'm posting these as a reminder to myself, but hopefully they'll help someone else, too!

Saturday, January 28, 2012

Setting up email in a Grails application using Zoho Mail

Goodness, that was a hassle! I love Zoho's mail, having used it as the email provider for my business for the past 8 or 9 months. It's inexpensive (free if you want 3 or fewer email addresses) and their tech support is prompt when a problem crops up.

However, I just spent the longest time (well over an hour) trying to get SMTP set up for an application I am building for my church. Since I'm sure I'll end up using Zoho for mail processing in the future, I figured I'd capture the steps here for both my future self and anyone else who might benefit.

  1. Set up a Zoho account. I create a new email address for my main domain using a name that matches the application I'm setting up the account for: newapplicationname@davidcastro.com.
  2. Validate the account using the link that is emailed to newapplicationname@davidcastro.com.
  3. Update the DNS settings by adding the CNAME required to validate ownership of the domain.
  4. Confirm domain ownership using the Zoho interface.
  5. Update the DNS settings by adding an MX entry to point to 20 mx2.zohomail.com and 10 mx.zohomail.com.
  6. Create an email account for mydomain.com: email@mydomain.com in the Zoho interface.
  7. Configure email forwarding to my main email address.
  8. Validate the forwarding by clicking the link in the email sent to my main email address.
  9. Install the Mail plugin into my Grails application.
  10. In Config.groovy, add the following:
  11. grails {
      mail {
        host = "smtp.zoho.com"
        username = "username"
        password = "password"                    
        port = 465
        props = ["mail.smtp.auth":"true",                        
                 "mail.smtp.socketFactory.port":"465",
                 "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
                 "mail.smtp.socketFactory.fallback":"false"]
      }
    }
    
  12. In the method that triggers the email being sent, add the following:
  13. sendMail {
      to "email@domain.com"
      from "Application Name <email@mydomain.com>"
      subject "Subject line"
      body "Body of message"
    }
    
  14. And now we move onto the tricky part. We need to enable SMTP in the Zoho account. To do this:
    1.  In Zoho Mail, click the Settings link in the upper left corner.
    2. Click the Email forwarding an POP/IMAP link on the left panel.
    3. In the IMAP Access section of the right panel, change Status to "Enable."
  15. Next, we need to add the Send Mail As setting to the Zoho account so that it knows that you're not sending as an email address you don't own (spoofing). To do this:
    1. In Zoho Mail, click the Settings link in the upper left corner.
    2. Click the Send Mail as link on the left panel.
    3. In the top of the right panel, click Add From Address.
    4. Enter a display name, the email address to send from (email@mydomain.com), and then select the Zoho SMTP option.
    5. Click Send verification.
    6. Give it a couple of minutes and then retrieve the confirmation number in the email sent to email@mydomain.com and paste it into the Zoho dialog box that popped up after you clicked Send verification.

Thursday, March 3, 2011

First Post

This blog chronicles my experience with Groovy on Grails in the projects that I work on for my clients and my own personal projects. It is my hope that some of what I post will help out others in the Grails community to become even faster at developing Grails solutions, to avoid or solve problems that I've encountered and conquered, or by providing new ideas that they may not have considered.