// Ick! This is incredibly ugly. I don't quite understand why there
// is not an easier way to generate a multipart/alternative message.
// However, this seems to work, so we'll go with it.
if (StringUtils.isEmpty(plaintext) || StringUtils.isEmpty(html)) {
throw new CedarRuntimeException("Must provide HTML and plaintext parts.");
}
MimeBodyPart plaintextPart = new MimeBodyPart();
plaintextPart.setText(plaintext);
plaintextPart.addHeaderLine("Content-Type: text/plain; charset=\"" + CHARSET + "\"");
plaintextPart.addHeaderLine("Content-Transfer-Encoding: quoted-printable");
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setText(html);
htmlPart.addHeaderLine("Content-Type: text/html; charset=\"" + CHARSET + "\"");
htmlPart.addHeaderLine("Content-Transfer-Encoding: quoted-printable");
Multipart content = new MimeMultipart("alternative");
content.addBodyPart(plaintextPart);
content.addBodyPart(htmlPart);
Message message = createBasicMessage(sender, recipients, replyTo, subject);
message.setContent(content);
return message;
} catch (CedarRuntimeException e) {
throw e;
} catch (Exception e) {
throw new CedarRuntimeException("Failed to create message: " + e.getMessage(), e);
}
}