2

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("testAccount@googlemail.com")
           sender_ref.setPassword("topsecret")
           message_ref.setTo("testRecipient@gmx.de")
           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.

Community
  • 1
  • 1
最白目
  • 3,505
  • 6
  • 59
  • 114

3 Answers3

2

Quoting from the Grails mail plugin docs:

grails {
   mail {
     host = "smtp.gmail.com"
     port = 465
     username = "youracount@gmail.com"
     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"]
} }
Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • Thank you, but the Mails Plug in doesnt work with my project, I try to fix it in this thread http://stackoverflow.com/questions/6692543/grails-mail-plugin-doesnt-install-try-to-fix-in-config-but-still-doesnt-work , but thanks anyway – 最白目 Jul 16 '11 at 06:56
1

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.

foozbar
  • 138
  • 1
  • 9
0
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);
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
  • the problems is often cause by not adding properties.put("mail.smtp.starttls.enable", "true"); as part of the properties – Adeniyi Adebambo Mar 26 '18 at 16:05
  • While this may answer the OP's question, a few words of explanation would help current and future users understand your answer even better. – Thom Mar 26 '18 at 17:17