尝试在 Grails 中发送 SimpleMailMessage 时必须首先发出 STARTTLS 命令

发布于 2024-11-25 00:28:44 字数 1193 浏览 1 评论 0原文

我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何止钟意 2024-12-02 00:28:44

引用 Grails 邮件插件 文档:

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"]
} }

Quoting from the Grails mail plugin docs:

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"]
} }
烈酒灼喉 2024-12-02 00:28:44

我帮不了你太多,但你的问题基本上是你需要使用 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.

短暂陪伴 2024-12-02 00:28:44
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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文