}
// now build the actual message
MimeMessage myMimeMessage = aMimeMessage;
// wrap it in a MimeMessageHelper - since some things are easier with that
MimeMessageHelper myMimeMessageHelper = new MimeMessageHelper(myMimeMessage);
// set headers
// subject
myMimeMessageHelper.setSubject
(
TextRenderUtil.getInstance().render
(
(String)propMap.get(MessageRefProp.JR_SUBJECT.toString()),
myRenderContext
)
);
// TODO: implement DKIM, figure out subetha
String mySenderEmailPattern = aSendConfig.getSenderEmailPattern();
String mySenderEmail = TextRenderUtil.getInstance().render(mySenderEmailPattern, myRenderContext);
myMimeMessage.setSender(new InternetAddress(mySenderEmail));
myMimeMessageHelper.setTo(aSubscriber.getEmail());
// from
myMimeMessageHelper.setFrom
(
TextRenderUtil.getInstance().render
(
(String)propMap.get(MessageRefProp.JR_FROM_EMAIL.toString()),
myRenderContext
),
TextRenderUtil.getInstance().render
(
(String)propMap.get(MessageRefProp.JR_FROM_NAME.toString()),
myRenderContext
)
);
// see how to set body
// if we have both text and html, then do multipart
if (myTextBody.trim().length() > 0 && myHtmlBody.trim().length() > 0) {
// create wrapper multipart/alternative part
MimeMultipart ma = new MimeMultipart("alternative");
myMimeMessage.setContent(ma);
// create the plain text
BodyPart plainText = new MimeBodyPart();
plainText.setText(myTextBody);
ma.addBodyPart(plainText);
// create the html part
BodyPart html = new MimeBodyPart();
html.setContent(myHtmlBody, "text/html");
ma.addBodyPart(html);
}
// if only HTML, then just use that
else if (myHtmlBody.trim().length() > 0) {
myMimeMessageHelper.setText(myHtmlBody, true);
}
// if only text, then just use that
else if (myTextBody.trim().length() > 0) {
myMimeMessageHelper.setText(myTextBody, false);
}
// if neither text nor HTML, then the message is being skipped,
// so we just return null
else {