在运行时更改邮件配置 [英] Changing mail configuration in runtime
问题描述
Config.grovy
中的配置是 grails {
mail {
host =
port = 0
username =
password =
props = []
}
带有值,所有的工作都是核心的,之后我试过重新配置
像这样
grailsApplication.config.grails.mail.host =smtp.gmail.com
grailsApplication.config.grails.mail.port = 465
grailsApplication.config.grails.mail.username =
从控制器,发现邮件正在从旧地址发送,调试后我发现邮件插件中有自动连线的实例,如code> mailSender ,一个明显的解决方案是重新创建 mailSender
并重新设置,但是根据Spring单例策略判断,这将是很难的解决方案,所以,我的问题是否有可能重新配置电子邮件在运行时没有类重新加载?
谢谢。
修复使用重新启动 mailsender
实例,但等待其他解决方案,谢谢
mailSender.setHost(smtp.gmail.com)
mailSender.setPort(465)
mailSender.setJavaMailProperties(new Properties(){
{
put(mail .smtp.auth,true);
put(mail.smtp.socketFactory.port,465);
put(mail.smtp.socketFactory.class,javax.net.ssl.SSLSocketFactory);
put(mail.smtp.socketFactory.fallback,false);
}
})
I've just started to investigate grails framework and first task I'm trying to resolve is sending email. Basic tutorial and community answers provided lot of information for quick start, and yes I've created simple app with possibility to send email. But, next point of my investigation was changing mail configuration in runtime. So, first my configuration in Config.grovy
was
grails {
mail {
host = ""
port = 0
username = ""
password = ""
props = [""]
}
}
with values, and all worked corectlly, after that I've tried to re-config it like that
grailsApplication.config.grails.mail.host = "smtp.gmail.com"
grailsApplication.config.grails.mail.port = 465
grailsApplication.config.grails.mail.username = ""
from controller, and found that mail is sending from old adress, after debugs I've found that there are auto-wired instances in mail plugins like mailSender
and one obvious solution is recreate mailSender
and re-set it, but judging to Spring singleton policy it will be hard solution, so, My question Are there possibilities to re-configure mail in runtime without class-reloading ?
Thanks.
Fixed using re-init mailsender
instance but waiting for other solutions, Thanks
mailSender.setHost("smtp.gmail.com")
mailSender.setPort(465)
mailSender.setJavaMailProperties(new Properties() {
{
put("mail.smtp.auth", "true");
put("mail.smtp.socketFactory.port", "465");
put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
put("mail.smtp.socketFactory.fallback", "false");
}
})
这篇关于在运行时更改邮件配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!