mimeMessage.setHeader(HEADER_PRIORITY, String.valueOf(email.getPriority().getRank()));
for (Iterator iter = email.getHeaders().entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
mimeMessage.setHeader(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
MimeMessageHelper message =
new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_RELATED, encoding);
message.setTo(email.getTo());
message.setBcc(email.getBcc());
message.setCc(email.getCc());
message.setFrom(email.getFrom());
message.setSubject(email.getSubject());
if (email.getTextBody() != null && email.getHtmlBody() != null) {
message.setText(email.getTextBody(), email.getHtmlBody());
} else {
if (email.getTextBody() != null) {
message.setText(email.getTextBody(), false);
}
if (email.getHtmlBody() != null) {
message.setText(email.getHtmlBody(), true);
}
}
if (email.getReplyTo() != null) {
message.setReplyTo(email.getReplyTo());
}
for (Iterator iter = email.getAttachments().iterator(); iter.hasNext();) {
Attachment attachment = (Attachment) iter.next();
message.addAttachment(attachment.getName(), attachment.getResource());
}
for (Iterator iter = email.getInlineAttachments().iterator(); iter.hasNext();) {
Attachment attachment = (Attachment) iter.next();
message.addInline(attachment.getName(), attachment.getResource());
}
}
};
}