尝试在 Grails 中发送 SimpleMailMessage 时必须首先发出 STARTTLS 命令
我尝试在 grails 应用程序中发送消息。我使用Java代码来解决这个问题,这是我的代码,
SimpleMailMessage message_ref = new SimpleMailMessage();
JavaMailSenderImpl sender_ref = new JavaMailSenderImpl();
sender_ref.setHost("smtp.gmail.com")
sender_ref.setUsername("[email protected]")
sender_ref.setPassword("topsecret")
message_ref.setTo("[email protected]")
message_ref.setSubject("Hello there")
message_ref.setText("How are you")
sender_ref.send(message_ref)
我得到以下异常:
SMTPSendFailedException:530 5.7.0 必须首先发出 STARTTLS 命令
我在 stackoverflow 上发现了类似的问题 必须先发出 STARTTLS 命令。使用 Java 和 Google Apps 发送电子邮件 但这对我没有帮助,因为他使用了不同的方法。
有人能告诉我出了什么问题吗?我希望错误不在代码中,而是在某些配置文件中,这就是我的知识边缘。
I try to send a message in a grails application. I use Java code with this problem tho, here is my code
SimpleMailMessage message_ref = new SimpleMailMessage();
JavaMailSenderImpl sender_ref = new JavaMailSenderImpl();
sender_ref.setHost("smtp.gmail.com")
sender_ref.setUsername("[email protected]")
sender_ref.setPassword("topsecret")
message_ref.setTo("[email protected]")
message_ref.setSubject("Hello there")
message_ref.setText("How are you")
sender_ref.send(message_ref)
I'm getting the following exception:
SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
I found a similar problem here on stackoverflow here
Must issue a STARTTLS command first. Sending email with Java and Google Apps
but it didn't help me cause he used an different approach.
Can somebody tell me what's wrong? I'm expecting the error is not in the code but in some configuration file and this is where my knowledge edges.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引用 Grails 邮件插件 文档:
Quoting from the Grails mail plugin docs:
我帮不了你太多,但你的问题基本上是你需要使用 SSL 与服务器通信。出于很多充分的理由,谷歌不允许纯文本通信。我对 grails 不太了解,但我认为它有某种 ssl 支持。如果没有,您最好在 javax.mail 中执行此操作。
StartTLS 只是您发送到 smtp 服务器以显式启动安全通信的文本命令。
I can't help you much, but your problem is basically that you need to use SSL to communicate with the server. Google does not allow plain-text communication for a lot of good reasons. I don't know much about grails, but I assume it has some sort of ssl-support. If it does not, you're probably better off doing it in javax.mail.
StartTLS is just a text-command you send to the smtp-server to explicitly start secure communications.