grails / grails-mail

The Grails Mail Plugin
https://grails.github.io/grails-mail/
Apache License 2.0
14 stars 25 forks source link

MessagingException on grails 3.1.0 #20

Closed ujjwol05 closed 7 years ago

ujjwol05 commented 7 years ago
application.yml 
grails:
            mail:
                host: "smtp.gmail.com"
                port: 465
                username: "*********@gmail.com"
                password: "**********"
                props:
                    mail.smtp.auth: "true"
                    mail.smtp.socketFactory.port: "465"
                    mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"
                    mail.smtp.socketFactory.fallback: "false"

Action

def create = {
        println "sending mail now............."
        sendMail {
            from "*********@gmail.com"
            to "**********@gmail.com"
            subject "New user"
            text "A new user has been created"
        }
        println "mail sent";
    }

ERROR

ERROR org.grails.web.errors.GrailsExceptionResolver - MessagingException occurred when processing request: [GET] /ims/test/create
Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Stacktrace follows:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
    at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:130) ~[mail-2.0.0.RC6.jar:na]
    at grails.plugins.mail.MailService.sendMail(MailService.groovy:53) ~[mail-2.0.0.RC6.jar:na]
    at grails.plugins.mail.MailService.sendMail(MailService.groovy:57) ~[mail-2.0.0.RC6.jar:na]
    at grails.plugins.mail.SendMail$Trait$Helper.sendMail(SendMail.groovy:31) ~[mail-2.0.0.RC6.jar:na]
sbglasius commented 7 years ago

It says, that it fails to connect to smtp.gmail.com on port 465. This is not a but in the mail plugin, but rather some connection issue on your localhost.

sbglasius commented 7 years ago

and by the way, it is not recommended to use closures as action definitions in Grails 2.x and up. You should change it to methods instead.

ujjwol05 commented 7 years ago

@sbglasius well I have another project that uses mail 1.0.7 on grails 2.4.2 and it's working fine. mail-2.0.0.RC6 on grails 3.1.0 gives me the error on the same config

sbglasius commented 7 years ago

You should try and convert your mail settings to application.groovy and use the old format. I'm not sure that the props: section gets passed back to the mail plugin correctly using application.yml

ujjwol05 commented 7 years ago

I even tried that one too.My config on application.groovy

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

And the error is same

ERROR org.grails.web.errors.GrailsExceptionResolver - MessagingException occurred when processing request: [GET] /ims/test/create
Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Stacktrace follows:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
    at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:130) ~[mail-2.0.0.RC6.jar:na]
    at grails.plugins.mail.MailService.sendMail(MailService.groovy:53) ~[mail-2.0.0.RC6.jar:na]
    at grails.plugins.mail.MailService.sendMail(MailService.groovy:57) ~[mail-2.0.0.RC6.jar:na]
    at ims.TestController.create(TestController.groovy:17) ~[main/:na]
    at grails.plugin.springsecurity.web.UpdateRequestContextHolderExceptionTranslationFilter.doFilter(UpdateRequestContextHolderExceptionTranslationFilter.groovy:64) ~[spring-security-core-3.1.1.jar:na]
    at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53) ~[spring-security-core-3.1.1.jar:na]
    at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62) ~[spring-security-core-3.1.1.jar:na]
    at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58) ~[spring-security-core-3.1.1.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0]
    at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2042) ~[javax.mail-1.5.4.jar:1.5.4]
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697) ~[javax.mail-1.5.4.jar:1.5.4]
    at javax.mail.Service.connect(Service.java:364) ~[javax.mail-api-1.5.4.jar:1.5.4]
    ... 11 common frames omitted
sbglasius commented 7 years ago

This example works: https://github.com/sbglasius/g3-tour-de-plugin-demo/blob/mail/grails-app/conf/application.groovy (notice, that it's on the tag mail)

The presentation is here: https://www.youtube.com/watch?v=RuK90qD6RJU

Notice, that the password in my example is set in an external file.

ujjwol05 commented 7 years ago

@sbglasius Today i tried the plugin for grails 3.0.2 and everything is working fine. I guess there is a issue for grails 3.1.0 . I tried installing the plugin several times but still the error is same. Which version of grails did you use for the presentation?

sbglasius commented 7 years ago

I used Grails 3.2.3

ujjwol05 commented 7 years ago

Thanks . It worked on other grails version . But there is a issue for 3.1.0