【发布时间】:2012-03-13 04:28:15
【问题描述】:
我正在使用 grails Async Mail 插件在我的应用程序中发送带有附件的电子邮件。为了实现这一点,我编写了以下代码
def sendEmail = {
def documentsInstances = Documents.getAll(params.list('ids[]'))
def s3Service = new AmazonS3Service()
documentsInstances.each(){documentsInstance->
asyncMailService.sendMail {
multipart true
to documentsInstance.author.emailAddress
subject 'Test';
html '<body><u>Test</u></body>';
attachBytes documentsInstance.filename , 'text/plain', s3Service.getBytes(session.uid,documentsInstance.filename);
}
}//
}
现在上面的代码几乎可以正常工作,但它会为每个附件发送一封电子邮件,我不确定如何将这个循环移动到发送邮件中,以便我可以在一封电子邮件中发送多个附件。
还有没有办法发送电子邮件,这样我就不必在 byte[] 中加载整个文件?
我正在使用 JetS3t 访问 Amazon S3,并尝试使用“附加”方法
new InputStreamResource(s3Obj.getDataInputStream())即
attach documentsInstance.filename , 'text/plain', new InputStreamResource(s3Obj.getDataInputStream());
但我得到了
"Passed-in Resource contains an open stream: invalid argument. JavaMail requires an InputStreamSource that creates a fresh stream for every call"
【问题讨论】:
标签: email grails plugins groovy