Grails 邮件插件:附加 org.springframework.web.multipart.commons.CommonsMultipartFile
我不知道如何做附件。已安装插件“mail”,并且相关文件是从表单(成功)上传的 .csv。
这有效:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
to "[email protected]"
subject "subject"
body bodyString
}
这不起作用:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
multipart true
to "[email protected]"
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)
I cannot figure out how to do attachments. Installed plugin "mail" and the file in question is a .csv being uploaded (successfully) from a form.
This works:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
to "[email protected]"
subject "subject"
body bodyString
}
This doesn't:
def f = request.getFile('uploadedFile')
//do a bunch of stuff with f and make bodyString
MailService.sendMail {
multipart true
to "[email protected]"
subject "subject"
body bodyString
attach "myfile.csv", f
}
Oh yeah the error says this:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 0.9 或更高版本的邮件插件,则以下内容应该可以
正常工作,您对邮件服务
MailService
的引用名称很特殊。如果您通过自动装配 Spring bean 来获取对此服务的引用,我希望它是mailService
If you're using version 0.9 or later of the mail plugin, the following should work
incidentally, the name of your reference to the mail service
MailService
is peculiar. If you're getting a reference to this service by autowiring the Spring bean, I would expect it to bemailService