2012-03-23 16 views
1

mail pluginを使用して、grailsアプリケーションから添付ファイル付きマルチパートメールを送信しています。tomcat6からマルチパートメールを送信するとIllegalStateExceptionが発生する

ローカルマシン(Mac OS X)ではすべて正常に動作します。私は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のバージョンを確認するにはどうすればよいですか?

答えて

0

私は問題の原因を見つけました。それは私自身の愚かな間違いでした。

mailServiceの呼び出しは次のようにデフォルトbccを追加するために、別のサービスにカプセル化されました:私はextraMail.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) 
} 

すべてが正常に動作します。

bccが設定された瞬間に、外側クロージャのmultipartプロパティがMailMessageBuilderでは無視されているようです。 - 私は、より正確なコードを掲載します次回私に

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) 
} 

恥を:

ソリューションは、以下に示すようにbccの位置を変更することでした。

関連する問題