Must issue a STARTTLS command first when trying to send a SimpleMailMessage in Grails
我尝试在 grails 应用程序中发送消息。我使用 Java 代码解决这个问题,这是我的代码
1 2 3 4 5 6 7 8 9 10 | 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 Must issue a STARTTLS command first
我在此处的 stackoverflow 上发现了类似的问题
必须首先发出 STARTTLS 命令。使用 Java 和 Google Apps 发送电子邮件
但这对我没有帮助,因为他使用了不同的方法。
有人能告诉我出了什么问题吗?我希望错误不在代码中,而是在一些配置文件中,这就是我的知识优势。
引自 Grails 邮件插件文档:
1 2 3 4 5 6 7 8 9 10 11 | grails { mail { host ="smtp.gmail.com" port = 465 username ="[email protected]" password ="yourpassword" props = ["mail.smtp.auth":"true", "mail.smtp.socketFactory.port":"465", "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory", "mail.smtp.socketFactory.fallback":"false"] } } |
我帮不了你太多,但你的问题基本上是你需要使用SSL与服务器通信。出于很多充分的理由,Google 不允许纯文本通信。我不太了解 grails,但我认为它有某种 ssl 支持。如果没有,您可能最好在 javax.mail.
中进行
StartTLS 只是您发送到 smtp 服务器以明确启动安全通信的文本命令。
1 2 3 4 5 6 | Properties properties = new Properties(); properties.put("mail.smtp.host", smtpHost); properties.put("mail.smtp.port", smtpPort); properties.put("mail.smtp.starttls.enable","true"); properties.put("mail.user", userName); properties.put("mail.password", password); |