开发者

Grails mail plugin: attach org.springframework.web.multipart.commons.CommonsMultipartFile

开发者 https://www.devze.com 2023-03-06 18:30 出处:网络
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.

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 "myemail@secretplace.com"
  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 "myemail@secretplace.com"
  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)


If you're using version 0.9 or later of the mail plugin, the following should work

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
}

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 be mailService

0

精彩评论

暂无评论...
验证码 换一张
取 消