2

I have a grails 2.2.1 app with mail plugin 1.0.1.

Mail delivery via Gmail smtp server works fine when I run the app locally (grails dev run-app), but fails on the production server (which is on the Jelastic cloud platform), which I deploy as a war file.

Config.groovy:

// Mail
grails {
   mail {
     host = "smtp.gmail.com"
     port = 465
     username = "aut********@gmail.com"   // *** = just blacked out
     password = "sun1******"              // *** = just blacked out
       props = ["mail.smtp.auth":"true",
                "mail.smtp.starttls.required": "false",
                "mail.smtp.socketFactory.port":"465",
                "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
                "mail.smtp.socketFactory.fallback":"false"]
   }
}

But I only have one mail plugin configuration, and therefore assume that the config applies for both development and production environment.

In fact, when I unzip the war file and check the class (in my case: Config$_run_closure2_closure8_closure13.class) via Decompiler, I can see the correct config values in there:

enter image description here

Enlarged: http://i.troll.ws/638ef33d.png

Error message:

Caused by: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 d47sm23030880eem.9 - gsmtp

    at grails.plugin.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:104)
    at grails.plugin.mail.MailService.sendMail(MailService.groovy:41)
    at MailGrailsPlugin$_configureSendMail_closure6.doCall(MailGrailsPlugin.groovy:170)
    at com.oritrack.core.ApiController.register(ApiController.groovy:212)
    ... 5 more
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 d47sm23030880eem.9 - gsmtp

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
    at javax.mail.Service.connect(Service.java:291)
    ... 9 more   

It is so weird that the authentication fails; so it's at least trying to connect to the right server; and the username/password in the Config.groovy is the only set of mail plugin config that I have in there. If it runs locally, it gotta run elsewhere.

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192

1 Answers1

1

When something works in development and not in production the usual culprit (from my experience) is dependencies. Check your WAR for multiple version of the same jar e.g. java-mail-1.0.jar and java-mail-1.2.jar. Don't limit your search to java-mail.jar, that was just an example.

If you find multiple versions of one jar, try removing one and deploying your war and if it works... huzzah!

To find what plugin is bringing in the jar use "grails dependency-report". Once you find out what is bringing in the jar you can remove it by doing something like this in BuildConfig.groovy using the excludes syntax.

 dependencies {
  compile("org.apache.shiro:shiro-quartz:1.1.0") {
    excludes("quartz")
  }
  runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.0') {
    excludes 'xalan'
    excludes 'xml-apis'
    excludes 'groovy'
 }
}

I have solved some very strange errors like this, one of them including http authentication that was failing due to multiple http-client jars.

John Rellis
  • 543
  • 3
  • 15