debugging - grails 邮件 : inline images working on localhost and not in test environment

标签 debugging grails localhost html-email

我正在将内联图像添加到本地主机上的邮件中:

inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()

效果很好。 当我部署到测试环境时,出现此错误:

Class
java.io.FileNotFoundException
Message
cannot use ./web-app/images/mailAssets/alert_header_pre.png as an attachment as it does not exist

使用此日志:

   Line | Method
->>  331 | inline      in grails.plugin.mail.MailMessageBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     20 | doCall      in de.docinsider.web.NotifierService$_contactUser_closure1
|     39 | sendMail .  in grails.plugin.mail.MailService
|     13 | contactUser in de.docinsider.web.NotifierService
|      7 | doCall . .  in de.docinsider.web.SendController$_closure1
|    195 | doFilter    in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter .  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker   in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run         in java.lang.Thread

如何避免这种情况?

我还考虑过通过以下方式实现资源加载器:

import org.springframework.context.ResourceLoaderAware
import org.springframework.core.io.ResourceLoader

class SendController implements ResourceLoaderAware {
    @Autowired
    ResourceLoader resourceLoader
    def notifierService

    def index() { }
    def welcome = {
        notifierService.contactUser(params.username, params.email, params.message)
        render view:"/send/feedback", model:[name:params.username, message:params.message]
     }

     void setResourceLoader(ResourceLoader resourceLoader) {
        resourceLoader = resourceLoader
    }

}

这也不起作用。

与:

 inline 'headerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/header_top.png')
                inline 'footerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/footer_bottom.gif')

在服务中。

最佳答案

我知道这是一个旧线程,但是我遇到了同样的问题,并发现服务器不知道图像的真实路径,而是使用字符串作为真实路径“./web-app/images/mailAssets/alert_header_pre.png”。

阅读本文post将帮助您获得真正的道路。 而不是:

inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()

使用这个:

inline 'footerImage', 'image/jpg', resourceLoader.getResource("/images/mailAssets/suchebottomre.gif").getFile()

您需要导入 org.springframework.core.io.Resource 或 org.springframework.core.io.ResourceLoader 并且您的 Controller 实现实现 org.springframework.context.ResourceLoaderAware 并声明 ResourceLoader resourcesLoader

测试于: 产品服务器:glassfish。 开发人员:Grails 2.3.7。

关于debugging - grails 邮件 : inline images working on localhost and not in test environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067018/

相关文章:

debugging - 在 Sublime Text 中隐藏行

c# - 独立调试窗口?

grails - 无法在STS 4.1.2上安装GGTS

tomcat - 我应该在 Tomcat 中的什么地方放置跨域 XML?

使用带插值的可变 URL 的 Apache proxypass

debugging - asyncio.get_event_loop() 在 FLASK_DEBUG=1 时抛出错误

java - 如何在 Grails 框架中获取 GSP 中的不同列表

json - Grails RestBuilder发送奇怪的JSON

javascript - AccessDenied 根据策略 : Policy Condition failed: ["eq", "$success_action_redirect"、 "http://localhost/"无效]

c++ - 如何检查给定调用站点的重载解决方案集