Grails Mail-Plugin and Custom EmailerService
Just had an old project that got both Grails Mail-plugin installed and also a custom EmailerService implemented. Problem was that both approaches are configuring a org.springframework.mail.javamail.JavaMailSenderImpl in two different ways.
Grails Mail-Plugin was doing it via following Closure:
[groovy title="grails-app/conf/Config.groovy"]
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "username@test.com"
password = "password"
props = [
"mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"
]
}
}
[/groovy]
Whereas EmailerService implementation was injected a dependency of type org.springframework.mail.javamail.JavaMailSenderImpl which was created in resources.groovy:
[groovy title="grails-app/conf/spring/resources.groovy"]
beans = {
mailSender(org.springframework.mail.javamail.JavaMailSenderImpl) {
host = 'smtp.gmail.com'
port = 465
username = 'test@test.com'
password = 'password'
javaMailProperties = [
'mail.smtp.auth': 'true',
'mail.smtp.socketFactory.port': '465',
'mail.smtp.socketFactory.class': 'javax.net.ssl.SSLSocketFactory',
'mail.smtp.socketFactory.fallback': 'false'
]
}
}
[/groovy]
So we got confused because both approaches were providing an org.springframework.mail.MailSender thus overwriting each other when injecting the dependency.


