簡體   English   中英

Groovy使用AntBuilder郵件附加多個文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM