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

标签 email grails service path

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

相关文章:

java - 当域名包含连字符时,电子邮件地址验证失败

php - 从 IMAP 邮箱中的电子邮件获取 IP

php, strtolower 和 mb_strtolower 有什么区别?

grails - Grails集合

android - 从服务通知 Activity

java - 不在 digital ocean 服务器中发送电子邮件

spring - 如何使用 Spring Integration 仅在事务成功完成时发送消息?

email - Grails - 动态更改邮件插件的配置

c# - Windows 服务和 Prism : Can the Service Reference Prism Assemblies?

android - 传递消息 : ServiceIntent not found 时出错