the*_*unt 2 debugging grails localhost html-email
我将内联图像添加到localhost上的邮件中:
inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.当我部署到我的测试环境时,我收到此错误:
Class
java.io.FileNotFoundException
Message
cannot use ./web-app/images/mailAssets/alert_header_pre.png as an attachment as it does not exist
Run Code Online (Sandbox Code Playgroud)
用这个日志:
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
Run Code Online (Sandbox Code Playgroud)
如何避免这种情况?
我还想要实现一个资源加载器:
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
}
}
Run Code Online (Sandbox Code Playgroud)
这也行不通.
附:
inline 'headerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/header_top.png')
inline 'footerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/footer_bottom.gif')
Run Code Online (Sandbox Code Playgroud)
在服务中.
我知道这是一个古老的线程,但我碰到了同样的问题,并发现该服务器不知道到图像中的真实路径,而是使用字符串作为真实路径" ./web-app/images/mailAssets/ alert_header_pre.png".
阅读这篇文章将帮助您获得真正的道路.代替:
inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()
Run Code Online (Sandbox Code Playgroud)
用这个:
inline 'footerImage', 'image/jpg', resourceLoader.getResource("/images/mailAssets/suchebottomre.gif").getFile()
Run Code Online (Sandbox Code Playgroud)
您将需要import org.springframework.core.io.Resource or org.springframework.core.io.ResourceLoader和您的控制器实现implements org.springframework.context.ResourceLoaderAware并声明ResourceLoader resourceLoader
测试:产品服务器:glassfish.Dev:Grails 2.3.7.
| 归档时间: |
|
| 查看次数: |
773 次 |
| 最近记录: |