2012-03-23 2 views
1

mail plugin을 사용하여 grails 애플리케이션에서 첨부 파일이있는 멀티 파트 메일을 보내고 있습니다.tomcat6에서 멀티 파트 메일을 보낼 때 IllegalStateException이 발생했습니다

내 로컬 컴퓨터 (Mac OS X)에서 정상적으로 작동합니다. 내가 tomcat6 내 응용 프로그램을 배포하는 경우 (우분투 -) 메일은 인해 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) 
     ... 

간단한 메일이 (으로 multipart되지 않음)를 성공적으로 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 lib는 어디에 있습니까? 전쟁 파일에 담겨 있습니까?

tomcat6 내 로컬 컴퓨터에서 어떤 버전의 JavaMail이 사용되는지 어떻게 알 수 있습니까?

답변

0

나는 문제의 근원을 발견했다. 그것은 내 자신의 어리석은 실수였다.

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을 지정 havn't는 때문에 모두가 잘 작동합니다.

바로 그 순간에 bcc이 설정되면 바로 닫는 부분의 multipart 속성이 MailMessageBuilder에서 무시되는 것 같습니다. 아래 그림과 같이

솔루션

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

부끄러운 날에 - 다음 번에 좀 더 정확한 코드를 게시 할 예정입니다.

관련 문제