[英]Groovy Attach multiple files with AntBuilder mail
我有下面的代码。 我的问题是我想发送零(或更多)文件,但我不确定该怎么做。 Ant要求您为文件集设置一个基本目录,但是对于这种方法,我不知道那是什么。 如何添加要附加的零个或多个文件的任意列表?
public void send(File[] files){
ant.mail (
from: "IMSBatch@vanguard.com",
tolist: to,
message: msg,
subject : subject,
mailhost: host,
messagemimetype: 'text/html'
){
attachments(){
fileset(dir: ????){
include(arbitrary list of files)
}
}
}
}
附带说明,我遇到了一个错误,当我在班上其他地方有setAttachments()
方法时,此代码实际上被破坏了。 我认为,无论是Ant还是Groovy,它们之间的名称和AntBuilder的attachments
方法之间都是混在一起的。
这样怎么样
@Grab(group='org.apache.ant', module='ant-javamail', version='1.9.4')
@Grab(group='javax.activation', module='activation', version='1.1.1')
@Grab(group='javax.mail', module='mail', version='1.4.7')
@GrabConfig(systemClassLoader=true)
// ...
public void send(File[] files) {
String filesString = ""
for (int i = 0; i < files.size(); i++) {
filesString += f.canonicalPath
if (files.size() > 1 && i < files.size() -1)
filesString += ","
}
ant.mail(
from: "IMSBatch@vanguard.com",
tolist: to,
message: msg,
subject: subject,
mailhost: host,
messagemimetype: "text/html",
files: filesString
)
}
可能有一种Groovier的方式来填充filesString
,我愿意提出改善答案的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.