Source:
<code>public void send(String recipient, String messageSubject, String messageBody) throws MessagingException { try { Message msg = new MimeMessage(session); msg.setFrom(from); InternetAddress address = new InternetAddress(recipient); msg.setRecipient(Message.RecipientType.TO, address); if (replyTo != null) { msg.setReplyTo(new Address[] { replyTo }); } msg.setSubject(messageSubject); if (isBodyHtml){ msg.setContent(String.format("<html><head><title>%s</title></head><body><p>%s</body></html>", messageSubject, messageBody), "text/html"); } else { msg.setText(messageBody); } msg.setSentDate(new Date()); if (isSSL) { Transport transport = session.getTransport("smtps"); transport.connect(); transport.sendMessage(msg, new Address[] { address }); } else { Transport.send(msg); } } catch (MessagingException mex) { StringBuilder errorMsg = new StringBuilder("Failed to send message "); if (from != null) { errorMsg.append(" from " + from.toString()); } if (StringUtils.isNotBlank(recipient)) { errorMsg.append(" to " + recipient); } if (StringUtils.isNotBlank(messageSubject)) { errorMsg.append(" with subject " + messageSubject); } <START> boolean firstProperty = true; <END> for (String key : session.getProperties().stringPropertyNames()) { errorMsg.append(firstProperty ? " (connection properties: " : ", "); firstProperty = false; errorMsg.append(key).append("=").append(session.getProperties().getProperty(key)); } if (auth != null) { if (!firstProperty) { errorMsg.append(", "); firstProperty = false; } errorMsg.append(auth); } if (!firstProperty) { errorMsg.append(")"); } errorMsg.append(" due to to error: " + mex.getMessage()); log.error(errorMsg.toString(), mex); throw mex; } }</code><technical_language>Please encapsulate this block in a method</technical_language>

Target:
public void send(String recipient, String messageSubject, String messageBody) throws MessagingException { try { Message msg = new MimeMessage(session); msg.setFrom(from); InternetAddress address = new InternetAddress(recipient); msg.setRecipient(Message.RecipientType.TO, address); if (replyTo != null) { msg.setReplyTo(new Address[] { replyTo }); } msg.setSubject(messageSubject); if (isBodyHtml){ msg.setContent(String.format("<html><head><title>%s</title></head><body><p>%s</body></html>", messageSubject, messageBody), "text/html"); } else { msg.setText(messageBody); } msg.setSentDate(new Date()); if (isSSL) { Transport transport = session.getTransport("smtps"); transport.connect(); transport.sendMessage(msg, new Address[] { address }); } else { Transport.send(msg); } } catch (MessagingException mex) { StringBuilder errorMsg = new StringBuilder("Failed to send message "); if (from != null) { errorMsg.append(" from " + from.toString()); } if (StringUtils.isNotBlank(recipient)) { errorMsg.append(" to " + recipient); } if (StringUtils.isNotBlank(messageSubject)) { errorMsg.append(" with subject " + messageSubject); } boolean firstProperty = true; firstProperty = parseSessionProperties(errorMsg, firstProperty); if (auth != null) { if (!firstProperty) { errorMsg.append(", "); firstProperty = false; } errorMsg.append(auth); } if (!firstProperty) { errorMsg.append(")"); } errorMsg.append(" due to to error: " + mex.getMessage()); throw mex; } }