grails - Grails邮件传递在本地工作正常,但在具有相同配置的实时服务器(Jelastic)上失败

标签 grails grails-plugin

我有一个Grails 2.2.1应用程序,带有邮件插件1.0.1。

当我在本地运行应用程序(grails dev run-app)时,通过Gmail smtp服务器的邮件传递工作正常,但在生产服务器(位于Jelastic云平台上)上的生产服务器上却失败了,我将其部署为war文件。

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"]
   }
}

但是我只有一个邮件插件配置,因此假定该配置适用于开发和生产环境。

实际上,当我解压缩war文件并通过Decompiler检查类(在我的情况下:Config $ _run_closure2_closure8_closure13.class)时,可以在其中看到正确的配置值:

放大:http://i.troll.ws/638ef33d.png

错误信息:
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   

认证失败很奇怪。因此,至少要尝试连接到正确的服务器;而Config.groovy中的用户名/密码是我在那里拥有的唯一一组邮件插件配置。如果在本地运行,则必须在其他位置运行。

最佳答案

当某些东西在开发中而不是在生产中起作用时,根据我的经验,通常的罪魁祸首就是依赖。检查您的WAR中是否有同一个jar的多个版本,例如java-mail-1.0.jar和java-mail-1.2.jar。不要将搜索限制为java-mail.jar,这只是一个示例。

如果您发现一个 jar 有多个版本,请尝试移除其中一个并部署您的 war ,如果它起作用了……

要查找将什么插件引入jar中,请使用“grails依赖关系报告”。一旦找到了jar中的内容,就可以通过使用excludes语法在BuildConfig.groovy中执行类似的操作来删除它。

 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'
 }
}

我已经解决了一些非常奇怪的错误,其中之一包括由于多个HTTP客户端jar导致HTTP身份验证失败的错误。

关于grails - Grails邮件传递在本地工作正常,但在具有相同配置的实时服务器(Jelastic)上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15751401/

相关文章:

grails - grails 索引页的最佳实践

grails run-war 导致 SLF4J : Class path contains multiple SLF4J bindings

grails - 我可以将Grails项目外的Grails插件类用作Jar依赖项吗?

hibernate - Hibernate映射在具有别名 “h002-01”的Grails中为列生成错误

sql - Grails数据库迁移-如何删除特定行?

java - 在运行时动态创建实体 - Spring boot、hibernate、Java 或使用 Gorm orm 的 Grails?

postgresql - 如何使用 GORM 将固定长度字符串映射到 Postgresql?

tomcat - Grails Tomcat 插件 - 找不到 DeployTask 错误

Grails 插件 Maven 集成

java - Grails 渲染插件 css 问题