Tutorial :Grails Mail port configuration


I am trying to send mail through grails mail plugin. I configured according to the documentation, and also followed few blog posts (http://blog.lourish.com/2010/04/02/sending-asynchronous-html-email-in-grails-with-activemq-jms-and-gmail/). That post mention that the closure way of declaring the configuration overrides others, but not true. Anyway I tried both approach, but seems like the port is still use the smtp default one. I get the below exception.

exception: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect  

Now, I wrote a small program directly using the java mail library, and I could send the mail with that. The configuration is shown below. tried additional config "mail.smtp.port":"465"", but no change.. used the parameters mentioned in the above blog post, result same

    grails {     mail {       host = "smtp.gmail.com"       port = "465"         username = "mylogin@gmail.com"       password = "mypwd"       props = ["mail.smtp.auth":"true",              // "mail.smtp.port":"465",                "mail.smtp.socketFactory.port":"465",                "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",                "mail.smtp.socketFactory.fallback":"false"]     }  }  

thanks in advance..

Update: It is not port or firewall config, as when I made a grails application from scratch, and tried with the same config, everything works. Also, asked in grails forum http://grails.1312388.n4.nabble.com/grails-mail-mailSender-does-not-have-config-values-td2237704.html#a2237704 . Hope get a lead to try.


I got it working with the help of this setting

grails {      mail {          host = "smtp.gmail.com"          port = 587          username = "xyz@gmail.com"          password = "mypassword"          props = ["mail.debug": "true",                  "mail.smtp.protocol": "smtps",                  "mail.smtp.auth": "true",                  "mail.smtp.starttls.enable": "true",                  "mail.smtp.host": "smtp.gmail.com",                  "mail.smtp.user": "xyz@gmail.com",                  "mail.smtp.password": "mypassword"]      }  }  


I think I solved the issue.. I had previously installed Nimble plugin, which also has a mail configuration injected into my application(NimbleConfig.groovy). It worked after I set the mail parameters as in my conf.groovy. I did not see that mailSender is initialized with the nimble config values, and only initialized once from my conf.groovy.. So, I am not sure about the reason, but it worked.


Maybe you should try to assign port property an integer value: port = 465 It works fine for me! Good luck!

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »