Source:
<code>public void send() throws MimeEmailException { if(getTo().isEmpty() && getCC().isEmpty() && getBCC().isEmpty()) { throw new MimeEmailException("The email's to, cc, and bcc fields are empty."); } try { Session session = null; try { <START> InitialContext initCtx = new InitialContext(); <END> Object obj = initCtx.lookup(EnvironmentConfig.INSTANCE.getSbtSessionResource()); if((obj instanceof Session)) { session = (Session)obj; } } catch (NameNotFoundException ex) { } if (session == null) { Context appCtx = Context.get(); Object obj = appCtx.getBean(EnvironmentConfig.INSTANCE.getSbtSessionFactoryResource()); if (!(obj instanceof MailSessionFactory)) { throw new MimeEmailException("Could not get valid Session object."); } session = ((MailSessionFactory) obj).getInstance(); } MimeMessage msg = new MimeMessage(session); msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getCommaSeparatedTo(), true)); msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(getCommaSeparatedCC(), true)); msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(getCommaSeparatedBCC(), true)); msg.setSubject(getSubject()); msg.setSentDate(new Date()); MimeMultipart mmp = new MimeMultipart("alternative"); MimeBodyPart bodyPart; for(MimePart part : getMimeParts()) { bodyPart = new MimeBodyPart(); bodyPart.setContent(part.getContent(), part.getMimeType()); Map<String, String> headers = part.getHeaders(); Set<String> keys = headers.keySet(); for(String key : keys) { bodyPart.addHeader(key, headers.get(key)); } mmp.addBodyPart(bodyPart); } msg.setContent(mmp); Transport.send(msg); } catch(Exception e) { throw new MimeEmailException(e); } }</code><technical_language>spacing messed</technical_language>

Target:
public void send() throws MimeEmailException { if (getTo().isEmpty() && getCC().isEmpty() && getBCC().isEmpty()) { throw new MimeEmailException( "The email's to, cc, and bcc fields are empty."); } try { Session session = null; try { InitialContext initCtx = new InitialContext(); Object obj = initCtx.lookup(EnvironmentConfig.INSTANCE .getSbtSessionResource()); if ((obj instanceof Session)) { session = (Session) obj; } } catch (NameNotFoundException ex) { logger.info(StringUtil.format( "JavaMail Session not bound in context at {0}, creating one from MailSessionFactory", EnvironmentConfig.INSTANCE.getSbtSessionResource())); } if (session == null) { Context appCtx = Context.get(); Object obj = appCtx.getBean(EnvironmentConfig.INSTANCE .getSbtSessionFactoryResource()); if (!(obj instanceof MailSessionFactory)) { throw new MimeEmailException( "Could not get valid Session object."); } session = ((MailSessionFactory) obj).getInstance(); } MimeMessage msg = new MimeMessage(session); msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(getCommaSeparatedTo(), true)); msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(getCommaSeparatedCC(), true)); msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(getCommaSeparatedBCC(), true)); msg.setSubject(getSubject()); msg.setSentDate(new Date()); MimeMultipart mmp = new MimeMultipart("alternative"); MimeBodyPart bodyPart; for (MimePart part : getMimeParts()) { bodyPart = new MimeBodyPart(); bodyPart.setContent(part.getContent(), part.getMimeType()); Map<String, String> headers = part.getHeaders(); Set<String> keys = headers.keySet(); for (String key : keys) { bodyPart.addHeader(key, headers.get(key)); } mmp.addBodyPart(bodyPart); } msg.setContent(mmp); Transport.send(msg); } catch (Exception e) { throw new MimeEmailException(e); } }