我尝试在 grails 应用程序中发送消息。我使用 Java 代码来解决这个问题,这是我的代码
SimpleMailMessage message_ref = new SimpleMailMessage();
JavaMailSenderImpl sender_ref = new JavaMailSenderImpl();
sender_ref.setHost("smtp.gmail.com")
sender_ref.setUsername("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f2b3a2c2b1e3c3c302a312b1f38303038333a323e3633713c3032" rel="noreferrer noopener nofollow">[email protected]</a>")
sender_ref.setPassword("topsecret")
message_ref.setTo("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98ecfdebeccafdfbf1e8f1fdf6ecd8fff5e0b6fcfd" rel="noreferrer noopener nofollow">[email protected]</a>")
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 上发现了类似的问题 Must issue a STARTTLS command first. Sending email with Java and Google Apps 但这对我没有帮助,因为他使用了不同的方法。
谁能告诉我出了什么问题吗?我预计错误不在代码中,而是在某些配置文件中,这就是我的知识边缘。
最佳答案
引自Grails mail plugin文档:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9c0d6cccbd8dad6ccd7cdf9ded4d8d0d597dad6d4" rel="noreferrer noopener nofollow">[email protected]</a>"
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"]
} }
关于java - 尝试在 Grails 中发送 SimpleMailMessage 时必须首先发出 STARTTLS 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6708154/