我使用grails邮件插件发送邮件,我必须从服务中发送电子邮件,并且从此我使用grails邮件插件:http://grails.org/plugin/mail
所以我有这段代码:
mailService.sendMail {
async true
to 'hello@world.fr'
from 'world@hello.fr'
subject subj
body (view:'/mail/_mailTemplate')
}
因此,现在一切正常,我的方法发送电子邮件。
在我的邮件模板中,我必须显示图像pippo.png,并且我以这种方式进行操作。
<img src="${resource(dir: 'images/mailImage', file: 'pippo.png',absolute:true)}">
在生成的html中,作为该图像结果的链接是:
http://localhost/images/mailImage/pippo.png
使用此链接很明显,邮件客户端将永远找不到该图像。
但是当我从 Controller 渲染相同的模板时,我得到:
http://www.mycorrectdomain/images/mailImage/pippo.png
因此,即使我从服务中渲染模板,也如何获得当前域?
最佳答案
在resource
标记的grails文档中,它说:
absolute (optional) - If true will prefix the link target address with the value of the grails.serverURL property from Config.groovy, or localhost if there is no setting in Config.groovy and not running in production.
因此,我猜测您看到localhost的原因是因为您尚未在
Config.groovy
中配置URL,或者您没有在生产模型中运行。要更改默认URL,请使用
Config.groovy
:grails.serverURL = "http://www.thecorrectwebsite.com"
要在生产模式下运行:
grails production run-app
应该可以解决问题。
关于email - 从服务grails调用的模板中获取当前域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25034750/