gpt4 book ai didi

email - 从服务grails调用的模板中获取当前域

转载 作者:行者123 更新时间:2023-12-02 15:27:54 25 4
gpt4 key购买 nike

我使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com