spring - Grails邮件插件:附加org.springframework.web.multipart.commons.CommonsMultipartFile

标签 spring email grails attachment

我不知道该怎么做附件。已安装插件“邮件”,相关文件是从表单上载(成功)的.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/

相关文章:

asp.net - 未指定 SMTP 主机

android - 通过电子邮件链接打开 Facebook 和 Instagram 应用程序

html - 如何通过仅选择Grails中的一个单选按钮来将两个不同的值分配给两个不同的变量?

grails - Grails 2.0缺陷NoClassDefFound问题

java - Hibernate Spring JPA session : A different object with the same identifier value was already associated with the session

java - 将 url 与 View 名称映射

forms - 在 Typo3 6.2.4 中使用 Powermail

java - Spring Batch 中如何维护数据库连接和事务

java - 如何在 spring MVC 的 Controller 中操作 jQuery AJAX JSON 数据

grails - 为什么 Grails Spring Security channel 安全性将我的 Controller 名称替换为 'grails' ?