Sending multi-part email from Google App Engine using Spring's JavaMailSender fails

Posted by hleinone on Stack Overflow See other posts from Stack Overflow or by hleinone
Published on 2010-04-21T22:07:03Z Indexed on 2010/04/21 22:13 UTC
Read the original article Hit count: 339

It works without the multi-part (modified from the example in Spring documentation):

final MimeMessagePreparator preparator = new MimeMessagePreparator() {
    public void prepare(final MimeMessage mimeMessage) throws Exception {
        final MimeMessageHelper message = new MimeMessageHelper(
                mimeMessage);
        message.setTo(toAddress);
        message.setFrom(fromAddress);
        message.setSubject(subject);
        final String htmlText = FreeMarkerTemplateUtils
                .processTemplateIntoString(configuration
                        .getTemplate(htmlTemplate), model);
        message.setText(htmlText, true);
    }
};
mailSender.send(preparator);

But once I change it to:

final MimeMessagePreparator preparator = new MimeMessagePreparator() {
    public void prepare(final MimeMessage mimeMessage) throws Exception {
        final MimeMessageHelper message = new MimeMessageHelper(
                mimeMessage, true);
...
        message.setText(plainText, htmlText);
    }
};
mailSender.send(preparator);

I get:

Failed message 1:
javax.mail.MessagingException: Converting attachment data failed
    at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:231)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:402)
...

This is especially difficult since the GMTransport is proprietary Google class and no sources are available, which would make it a bit easier to debug. Anyone have any ideas what to try next?

My bean config, for helping you to help me:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"
        p:username="${mail.username}" p:password="${mail.password}"
        p:protocol="gm" />

© Stack Overflow or respective owner

Related posts about spring

Related posts about java