Grails电子邮件插件发送电子邮件失败

时间:2014-02-10 05:25:29

标签: spring email grails javamail

我在项目中使用了grails电子邮件插件。

最初,我使用gmail帐户配置(官方网站上的文档)进行测试,我可以成功发送电子邮件。

但是,当我收到客户的电子邮件帐户详细信息并将其放在那里时,它无法正常工作。

我对grails的配置是:

grails {
        mail {
            host = "xxx.xxx.dev.xx"
            port = 25
            username = "xx.xx@xx.com"
            password = "secret"
            props = ["mail.smtp.auth": "true",
                    "mail.smtp.socketFactory.port": "25",
                    "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
                    "mail.smtp.socketFactory.fallback": "true"]
        }
    }

抛出的异常是:

| Error Exception in thread "Thread-42" 
| Error org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: xx.xx.dev.xx, port: 25;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: mailhost.powerdev.dev.int, port: 25;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?; message exception details (1) are:
| Error Failed message 1:
| Error javax.mail.MessagingException: Could not connect to SMTP host: mailhost.powerdev.dev.int, port: 25;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
| Error     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
| Error     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
| Error     at javax.mail.Service.connect(Service.java:291)
| Error     at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389)
| Error     at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
| Error     at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:336)
| Error     at org.springframework.mail.javamail.JavaMailSender$send$0.call(Unknown Source)
| Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
| Error     at grails.plugin.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:104)
| Error     at grails.plugin.mail.MailMessageBuilder$sendMessage$0.call(Unknown Source)
| Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
| Error     at grails.plugin.mail.MailService.sendMail(MailService.groovy:41)
| Error     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error     at java.lang.reflect.Method.invoke(Method.java:606)
| Error     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error     at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
| Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error     at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
| Error     at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
| Error     at sun.reflect.GeneratedMethodAccessor593.invoke(Unknown Source)
| Error     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error     at java.lang.reflect.Method.invoke(Method.java:606)
| Error     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error     at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80)
| Error     at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1108)
| Error     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error     at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
| Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
| Error     at au.com.jemena.edp.service.email.AsynchronousEmailService$1.run(AsynchronousEmailService.groovy:12)
| Error Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
| Error     at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:671)
| Error     at sun.security.ssl.InputRecord.read(InputRecord.java:504)
| Error     at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
| Error     at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
| Error     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
| Error     at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
| Error     at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:503)
| Error     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:234)
| Error     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
| Error     ... 37 more

我在这里想念一下吗?

1 个答案:

答案 0 :(得分:1)

您正在使用SSLSocketFactory表示SMTP正在运行SSL,但您正在使用端口25表示SMTP未运行SSL。选择一个:),使用端口465或不使用SSLSocketFactory

对于没有SSL的连接尝试类似这样的事情:

grails {
    mail {
        host = "smtp.example.com"
        port = 25
        username = "acount@example.com"
        password = "password"
        props = [ "mail.smtp.auth":"true" ]
    }
}