Source:
public void sendEmail() throws MessagingException { checkSettings(); Properties props = new Properties(); props.put("mail." + protocol + ".host", _mailHost); props.put("mail." + protocol + ".auth", "true"); props.put("mail.user", _mailUser); props.put("mail.password", _mailPassword); props.put("mail." + protocol + ".timeout", _mailTimeout); props.put("mail." + protocol + ".connectiontimeout", _connectionTimeout); props.put("mail.smtp.starttls.enable", _tls); props.put("mail.smtp.ssl.trust", _mailHost); Session session = Session.getInstance(props, null); Message message = new MimeMessage(session); InternetAddress from = new InternetAddress(_fromAddress, false); message.setFrom(from); for (String toAddr : _toAddress) message.addRecipient(Message.RecipientType.TO, new InternetAddress( toAddr, false)); message.setSubject(_subject); message.setSentDate(new Date()); if (_attachments.size() > 0) { MimeMultipart multipart = new MimeMultipart("related"); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(_body.toString(), _mimeType); multipart.addBodyPart(messageBodyPart); for (BodyPart part : _attachments) { multipart.addBodyPart(part); } message.setContent(multipart); } else { message.setContent(_body.toString(), _mimeType); } SMTPTransport t = (SMTPTransport) session.getTransport(protocol); try { t.connect(_mailHost, _mailUser, _mailPassword); } catch (MessagingException ste) { if (ste.getCause() instanceof SocketTimeoutException) { try { t.connect(_mailHost, _mailUser, _mailPassword); logger .info("Email retry on SocketTimeoutException completed successfully"); } catch (MessagingException me) { logger.info("Email retry on SocketTimeoutException failed"); throw me; } } else { throw ste; } } t.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); t.close(); }

Target:
public void sendEmail() throws MessagingException { checkSettings(); Properties props = new Properties(); if (_usesAuth) { props.put("mail." + protocol + ".auth", "true"); props.put("mail.user", _mailUser); props.put("mail.password", _mailPassword); } else { props.put("mail." + protocol + ".auth", "false"); } props.put("mail." + protocol + ".host", _mailHost); props.put("mail." + protocol + ".timeout", _mailTimeout); props.put("mail." + protocol + ".connectiontimeout", _connectionTimeout); props.put("mail.smtp.starttls.enable", _tls); props.put("mail.smtp.ssl.trust", _mailHost); Session session = Session.getInstance(props, null); Message message = new MimeMessage(session); InternetAddress from = new InternetAddress(_fromAddress, false); message.setFrom(from); for (String toAddr : _toAddress) message.addRecipient(Message.RecipientType.TO, new InternetAddress( toAddr, false)); message.setSubject(_subject); message.setSentDate(new Date()); if (_attachments.size() > 0) { MimeMultipart multipart = new MimeMultipart("related"); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(_body.toString(), _mimeType); multipart.addBodyPart(messageBodyPart); for (BodyPart part : _attachments) { multipart.addBodyPart(part); } message.setContent(multipart); } else { message.setContent(_body.toString(), _mimeType); } SMTPTransport t = (SMTPTransport) session.getTransport(protocol); try { connectToSMTPServer(t); } catch (MessagingException ste) { if (ste.getCause() instanceof SocketTimeoutException) { try { connectToSMTPServer(t); logger.info("Email retry on SocketTimeoutException succeeded"); } catch (MessagingException me) { logger.error("Email retry on SocketTimeoutException failed", me); throw me; } } else { logger.error("Encountered issue while connecting to email server", ste); throw ste; } } t.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); t.close(); }