Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从tomcat6发送多部分邮件时出现IllegalStateException_Java_Grails_Ubuntu_Tomcat6_Jakarta Mail - Fatal编程技术网

Java 从tomcat6发送多部分邮件时出现IllegalStateException

Java 从tomcat6发送多部分邮件时出现IllegalStateException,java,grails,ubuntu,tomcat6,jakarta-mail,Java,Grails,Ubuntu,Tomcat6,Jakarta Mail,我正在使用从grails应用程序发送带有附件的多部分邮件 在我的本地机器(MacOSX)上,一切正常。如果我将我的应用程序部署到tomcat6(Ubuntu-),邮件将无法发送,因为出现了IllegalStateException: Stacktrace follows: java.lang.IllegalStateException: Not in multipart mode - create an appropriate MimeMessageHelper via a co

我正在使用从grails应用程序发送带有附件的多部分邮件

在我的本地机器(MacOSX)上,一切正常。如果我将我的应用程序部署到tomcat6(Ubuntu-),邮件将无法发送,因为出现了
IllegalStateException

Stacktrace follows: 
   java.lang.IllegalStateException: Not in multipart mode - 
   create an appropriate MimeMessageHelper via a constructor that takes a 'multipart' 
   flag if you need to set alternative texts or add inline elements or attachments. 
      at grails.plugin.mail.MailMessageBuilder.doAdd(MailMessageBuilder.groovy:347) 
      at grails.plugin.mail.MailMessageBuilder.attach(MailMessageBuilder.groovy:308) 
      at grails.plugin.mail.MailMessageBuilder.attach(MailMessageBuilder.groovy:284) 
      at grails.plugin.mail.MailMessageBuilder.attachBytes(MailMessageBuilder.groovy:280)
      ...
简单邮件(不是多部分邮件)可以从tomat6成功发送

以下是我发送多部分邮件的代码:

mailService.sendMail {
   multipart true
   to mail
   subject mySubject
   body (view: myView, model: myModel)
   attachBytes "${myTitle}.pdf", CH.config.grails.mime.types['pdf'], myBytes
} 
如何避免这些异常

底层JavaMail库位于哪里?它被打包成战争档案了吗


我怎样才能知道我的tomcat6和本地机器上使用了哪个版本的JavaMail?

我找到了问题的根源——这是我自己犯的一个愚蠢的错误

mailService
的调用被封装到另一个服务中,以以下方式添加默认的
bcc

def sendWithBcc(Closure callable) {
    // build a wrapper closure around the standard mail closure, which adds BCC functionality
    def newMailClosure = {
        if(CH.config.extraMail.bcc) {
            bcc(CH.config.extraMail.bcc)
        }

        // set the delegate of the inner closure to the delegate of this closure and call the inner closure
        callable.delegate = delegate
        callable.resolveStrategy = Closure.DELEGATE_FIRST
        callable.call()
    }

    return mailService.sendMail(newMailClosure)
}
在我的本地机器上,一切正常,因为我没有指定
extraMail.bcc

就在设置
bcc
时,
MailMessageBuilder
中似乎忽略了外部闭包的multipart属性

解决方案是改变
bcc
的位置,如下所示:

def sendWithBcc(Closure callable) {
    // build a wrapper closure around the standard mail closure, which adds BCC functionality
    def newMailClosure = {            
        // set the delegate of the inner closure to the delegate of this closure and call the inner closure
        callable.delegate = delegate
        callable.resolveStrategy = Closure.DELEGATE_FIRST
        callable.call()

        if(CH.config.extraMail.bcc) {
            bcc(CH.config.extraMail.bcc)
        }
    }

    return mailService.sendMail(newMailClosure)
}
真丢脸-下次我会发布更精确的代码