Grails 邮件插件无法正常工作
我正在尝试从 Grails 应用程序发送邮件,但没有成功。
我使用过 gmail 和其他 smtp 服务器(没有 ssl!),但出现了同样的错误:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?. Failed messages: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?; message exceptions (1) are: Failed message 1: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
我在 Config.groovy 中使用(gmail 的示例):
grails.mail.host = "smtp.gmail.com" grails.mail.from = "[email protected]" grails.mail.port = "465" grails.mail.ssl = "on" grails.mail.username = "[email protected]" grails.mail.password = "xxx" grails.mail.props = ["mail.smtp.auth": "true", "mail.smtp.socketFactory.port": "465", "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory", "mail.smtp.socketFactory.fallback": "false", "mail.smtp.starttls.enable": "true", "mail.debug": "true"]
编辑:我制作了一个简单的应用程序,仅包含邮件插件和控制器以及Javid Jamae 发布的配置有效(第三个答案,我也认为另一个应该有效)。
但即使我只是复制粘贴相同的配置和相同的发送邮件代码,在我的主要项目中它仍然给我同样的异常!我认为这可能是由 Nimble 插件引起的(邮件插件是由它安装的)。 我的配置是:
Grails 版本:1.3.4
Groovy 版本:1.7.4
JVM版本:1.6.0_21
jquery - 1.4.2.5
邮件 - 0.9
希罗 - 1.0.1
nimble - 0.4-SNAPSHOT
最终编辑: 我解决了这个问题:看来我也必须在 Nimble 插件中使用相同的设置,在 NimbleConfig.groovy -> mail { ... (必须有“from = ...”) } .
愚蠢的问题,但浪费了很多时间。
I am trying to send mails from a Grails application, but without any success.
I've used gmail and other smtp server (without ssl!) but the same error occurs:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?. Failed messages: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?; message exceptions (1) are: Failed message 1: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
I am using in Config.groovy (example for gmail):
grails.mail.host = "smtp.gmail.com" grails.mail.from = "[email protected]" grails.mail.port = "465" grails.mail.ssl = "on" grails.mail.username = "[email protected]" grails.mail.password = "xxx" grails.mail.props = ["mail.smtp.auth": "true", "mail.smtp.socketFactory.port": "465", "mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory", "mail.smtp.socketFactory.fallback": "false", "mail.smtp.starttls.enable": "true", "mail.debug": "true"]
EDIT: I made a simple app with just the mail plugin and a controller and the config posted by Javid Jamae works (3rd answer, also I think the other should work).
BUT even if I just copy-paste the same config and the same sending mail code, on my primary project it still gives me the same exception! I think this can be caused by Nimble plugin (Mail plugin was installed by it).
My configuration is:
Grails version: 1.3.4
Groovy version: 1.7.4
JVM version: 1.6.0_21
jquery - 1.4.2.5
mail - 0.9
shiro - 1.0.1
nimble - 0.4-SNAPSHOT
FINAL EDIT :
I resolved the issue: it seems that I have to use the same settings in the Nimble plugin also, in NimbleConfig.groovy -> mail { ... (must have "from = ...") } .
Stupid issue, but waisted a lot of time on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我没有使用 SSL,并且在 Config.groovy 底部定义了以下内容(不在环境部分下):
我正在使用:
这对我有用。
I'm not using SSL and I have the following defined at the bottom of my Config.groovy (not under the environments section):
I'm using:
This works for me.
您已启用 SSL:
并得到异常
因此禁用 SSL(我的配置):
无论如何,如果您想启用 SSL - 尝试 587 端口。
也尝试设置
因为如果服务器不支持安全连接或客户端不接受服务器的证书,安全连接将不会启动,您将得到异常。
但是在设置 starttls.required = true 且安全连接不可能之后,整个连接将失败,因此您会收到正确的异常消息。
PS 请注意,SSL 和 TLS - 是不同的协议。
You have enabled SSL:
And got exception
So disable SSL (my config):
Anyway, if you want to enable SSL - try 587 port.
Also try to set
Because if server not supports secure connection or client doesn't accept server's certificate secure connection will not started and you will got your exception.
But after setting starttls.required = true and secure connection is impossible whole connection will fails so you got proper exception message.
P.S. Take a note that SSL and TLS - is different protocols.
我的配置中没有这一行
,并且我的连接正常工作
,端口也不应该用引号引起来
I dont have this line in my configuration
and my connection is working
also the port should not be in quotes
我也遇到过类似的问题,所以我将分享我的经验。使用 Nimble 插件(使用 Mail 插件作为依赖项)时,Nimble 在 grails-app/conf/NimbleConfig.groovy 中定义自己的邮件设置。
NimbleConfig.groovy
中的设置似乎覆盖了Config.groovy
中的设置(大概是因为NimbleConfig
是在Config
之后执行的) >)。这里的解决方案是有条件的:
如果您使用 Nimble,请在
grails-app/conf/NimbleConfig.groovy
中设置邮件属性;您不需要在grails-app/conf/Config.groovy
中设置它们
如果您不使用 Nimble,则只需按照 Mail 插件说明进行操作即可配置(或使用 Javid Jamae 的答案)
这似乎就是 OP在他/她的编辑中提到,但我只是想我会根据我对正在发生的事情的理解来确认编辑。
更新:
作为参考,以下是对我有用的
NimbleConfig.groovy
设置:I ran into a similar strain of this issue as well, so I'll share my experience. When using the Nimble plugin (which uses the Mail plugin as a dependency), Nimble defines its own mail settings in
grails-app/conf/NimbleConfig.groovy
.The settings in
NimbleConfig.groovy
appear to overwrite those set inConfig.groovy
(presumably becauseNimbleConfig
is executed afterConfig
).The solution here is conditional:
If you're using Nimble, set the mail properties in
grails-app/conf/NimbleConfig.groovy
; you do not need to set them ingrails-app/conf/Config.groovy
If you're not using Nimble, then just follow the Mail plugin instructions for configuration (or use Javid Jamae's answer)
This seems to be what the OP alluded to in his/her edits, but I just thought I'd confirm the edits with my understanding of what's happening.
Update:
For a reference, here are the
NimbleConfig.groovy
settings that worked for me:您可以通过检查在运行时验证您的配置设置
mailService.mailSender 属性。类似这样的内容:
mailService.mailSender.properties.each{println}
它将产生主机、端口、用户名、密码和一些其他值。
如果您确定它们都是正确的,我会怀疑防火墙问题。
You can verify your config settings at runtime by checking the
mailService.mailSender properties.Something like this:
mailService.mailSender.properties.each{println}
It will yield the host, port, username, password and a few other values.
If you're sure they are all correct, I would suspect a firewall issue.