grails / grails-mail

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

Not sending mail when I call mailService.sendMail from my controller. #3

Closed puneetbehl closed 8 years ago

puneetbehl commented 9 years ago

Here is the link to my sample application https://github.com/puneetbehl/grails3maildemo

puneetbehl commented 9 years ago

It seems like the issue is with mail configurations i.e.

props: [
 'mail.smtp.auth'                  : true,
 'mail.smtp.socketFactory.port'    : 465,
 'mail.smtp.socketFactory.class'   : 'javax.net.ssl.SSLSocketFactory',
 'mail.smtp.socketFactory.fallback': 'false'
]

is transformed into

props: [ mail: [ smtp: [ auth : true, socketFactory: [ port:465, class: 'javax.net.ssl.SSLSocketFactory', fallback: 'false' ] ] ] ]

For now I've implemented a workaround in Mail plugin https://github.com/puneetbehl/grails3mail-plugin/blob/master/src/main/groovy/grails/plugins/mail/MailGrailsPlugin.groovy

osscontributor commented 9 years ago

This is related to grails/grails-core#634.

puneetbehl commented 9 years ago

@jeffbrown I've made workaround in Mail plugin so that we are able send emails. Please click here to see my changes https://github.com/puneetbehl/mail/commit/caa33402c41f6ebfe25e54e46f9bcb8b00e8d3cc. I've already submitted a pull request fixing this issue, Let me know if I need to change anything in my workaround. I know that this is a temporary fix. But,I was also working on migrating the grails-asynchronous-mail plugin to Grails3 and my version will not work unless the mail plugin works as well. But I also like the idea about the separate plugin to fix this issue until the grails/grails-core#634. issue is fixed.

Waiting to hear from you.

bbooth commented 9 years ago

Running into the same thing. I tried to work around this by configuring my own JavaMailSender but the plugin always creates it own. I also added an application.groovy to attempt to use my old config from the 2.3.11 app I am converting, but that gives the same problem. I realize this is probably a larger grails-core issue, but wanted to document some of the attempted work arounds for others.

bbooth commented 9 years ago

Was able to work around this without having to modify the plugin nor build a plugin that runs before the mail plugin. I just added a listener when the application context was setup and fixed the bean.

@Component
class MailConfig implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    void onApplicationEvent(ContextRefreshedEvent event) {
        Properties props = new Properties();
        props.setProperty("mail.smtp.auth", "true")
        props.setProperty("mail.smtp.socketFactory.port", "465")
        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory")
        props.setProperty("mail.smtp.socketFactory.fallback", "false")

        JavaMailSenderImpl mailSender = event.applicationContext.getBean("mailSender")
        mailSender.javaMailProperties = props
    }

}
magbeat commented 9 years ago

@bbooth Thanks for the work around! Where did you have to put the MailConfig.groovy source code file? Did you have to adapt the ComponentScan somewhere. We tried to put it in src/main/groovy/ but it was not picked up when starting the Grails application with bootRun.

bbooth commented 9 years ago

I added it to my application.yml

grails:
    mail:
        host: smtpout.secureserver.net
        port: 465
        username: my-username
        password: my-password
        default:
            from: me@email.com
volnei commented 9 years ago

Not fixed on Grails 3.0.2 although grails/grails-core#634 was fixed

felansu commented 8 years ago

This bug is fixed on grails 3.0.1 ?

felansu commented 8 years ago

Solved and working on Grails 3.0.1 with 2.0.0.RC2 !

osscontributor commented 8 years ago

@felansu Thanks for the feedback.