Reputation: 862
I want the Grails' Mail plugin to read configuration properties from external properties file in class path. I have added this line in Config.groovy,
grails.config.locations = [
"classpath:app-${grails.util.Environment.current.name}-config.properties"]
and I have put properties in that file like this,
grails.mail.host = smtp.gmail.com
grails.mail.port = 465
grails.mail.username = username
grails.mail.password = password
all this work fine. The problem is that, the Mail plugin requires one more property that is of type Map. If we put that property in Config.groovy, I looks like this,
grails {
mail {
props = ["mail.smtp.auth" : "true",
"mail.smtp.socketFactory.port" : "465",
"mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"]
}
}
Now if I put this in external file as following,
grails.mail.props = ["mail.smtp.auth" : "true",
"mail.smtp.socketFactory.port" : "465",
"mail.smtp.socketFactory.class" : "javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback": "false"]
than it does not work. I need to read props Map from external file. I have searched a lot but in vain. Help is appreciated.
Upvotes: 3
Views: 924
Reputation: 2789
You can load configuration from external *.groovy
file where you can have maps etc. like in Config.groovy
. Create for example mail-config.groovy
with content as below:
grails {
mail {
host = smtp.gmail.com
port = 465
username = username
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"]
}
}
And point Grails to use it:
grails.config.locations = ["classpath:mail-config.groovy"]
Upvotes: 5