* @throws EmailException EmailException
* @throws MessagingException MessagingException
*/
private void build() throws MessagingException, EmailException
{
MimeMultipart rootContainer = this.getContainer();
MimeMultipart bodyEmbedsContainer = rootContainer;
MimeMultipart bodyContainer = rootContainer;
BodyPart msgHtml = null;
BodyPart msgText = null;
rootContainer.setSubType("mixed");
// determine how to form multiparts of email
if (EmailUtils.isNotEmpty(this.html) && this.inlineEmbeds.size() > 0)
{
//If HTML body and embeds are used, create a related container and add it to the root container
bodyEmbedsContainer = new MimeMultipart("related");
bodyContainer = bodyEmbedsContainer;
this.addPart(bodyEmbedsContainer, 0);
//If TEXT body was specified, create a alternative container and add it to the embeds container
if (EmailUtils.isNotEmpty(this.text))
{
bodyContainer = new MimeMultipart("alternative");
BodyPart bodyPart = createBodyPart();
try
{
bodyPart.setContent(bodyContainer);
bodyEmbedsContainer.addBodyPart(bodyPart, 0);
}
catch (MessagingException me)
{
throw new EmailException(me);
}
}
}
else if (EmailUtils.isNotEmpty(this.text) && EmailUtils.isNotEmpty(this.html))
{
//If both HTML and TEXT bodies are provided, create a alternative container and add it to the root container
bodyContainer = new MimeMultipart("alternative");
this.addPart(bodyContainer, 0);
}
if (EmailUtils.isNotEmpty(this.html))
{
msgHtml = new MimeBodyPart();
bodyContainer.addBodyPart(msgHtml, 0);
// apply default charset if one has been set
if (EmailUtils.isNotEmpty(this.charset))
{
msgHtml.setContent(
this.html,
Email.TEXT_HTML + "; charset=" + this.charset);
}
else
{
msgHtml.setContent(this.html, Email.TEXT_HTML);
}
Iterator iter = this.inlineEmbeds.values().iterator();
while (iter.hasNext())
{
InlineImage ii = (InlineImage) iter.next();
bodyEmbedsContainer.addBodyPart(ii.getMbp());
}
}
if (EmailUtils.isNotEmpty(this.text))
{
msgText = new MimeBodyPart();
bodyContainer.addBodyPart(msgText, 0);
// apply default charset if one has been set
if (EmailUtils.isNotEmpty(this.charset))
{
msgText.setContent(