Debugging grails mail:内联映像在本地主机上工作,而不是在测试环境中工作
我正在通过以下方式将内联图像添加到本地主机上的邮件中:Debugging grails mail:内联映像在本地主机上工作,而不是在测试环境中工作,debugging,grails,localhost,html-email,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_he
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
如何避免这种情况
我还想到了如何通过以下方式实现resourceloader:
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
}
}
这也不起作用
与:
在服务中。我知道这是一个旧线程,但是我遇到了同样的问题,发现服务器不知道图像的真实路径,而是使用字符串作为真实路径“/web app/images/mailAssets/alert\u header\u pre.png” 阅读这篇文章将帮助你找到真正的路径。 而不是:
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
,您的控制器实现实现org.springframework.context.ResourceLoaderware
并声明ResourceLoader ResourceLoader
测试日期:
Prod服务器:glassfish。
Dev:Grails 2.3.7.不应该是
resourceLoader.getResource('/images/mailsets/header_top.png').file.readBytes()
?不,这段代码是从webapp中的另一个工作位置复制粘贴的,唯一的区别是,它是从服务调用的,在另一个位置直接调用sendMail。请将解决方案作为此问题的实际答案发布,并将其标记为已解决问题。
inline 'footerImage', 'image/jpg', resourceLoader.getResource("/images/mailAssets/suchebottomre.gif").getFile()