我不知道该怎么做附件。已安装插件“邮件”,相关文件是从表单上载(成功)的.csv文件。
这有效:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
to "myemail@secretplace.com"
subject "subject"
body bodyString
}
这不是:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
multipart true
to "myemail@secretplace.com"
subject "subject"
body bodyString
attach "myfile.csv", f
}
哦,是的,错误说明了这一点:
groovy.lang.MissingMethodException: No signature of method: my_project.MySweetController.attach() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.springframework.web.multipart.commons.CommonsMultipartFile) values: [Demo myfile.csv, org.springframework.web.multipart.commons.CommonsMultipartFile@73e2d16b]
Possible solutions: each(groovy.lang.Closure)
最佳答案
如果您使用的是0.9版或更高版本的邮件插件,则应该可以执行以下操作
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
multipart true
to "myemail@secretplace.com"
subject "subject"
body bodyString
attachBytes "Some-File-Name.csv", "text/csv", f.bytes
}
顺便说一句,您对邮件服务
MailService
的引用名称很特殊。如果您通过 Autowiring Spring bean获得对该服务的引用,我希望它是mailService
关于spring - Grails邮件插件:附加org.springframework.web.multipart.commons.CommonsMultipartFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053781/