Source:
public void run(BatchActionContext context) throws Exception { if (!config.shouldRun(context)) { return; } config.validate(context.getFailureCollector()); Authenticator authenticator = null; Properties javaMailProperties = new Properties(); javaMailProperties.put("mail.smtp.host", config.host); javaMailProperties.put("mail.smtp.port", config.port); if (!(Strings.isNullOrEmpty(config.username))) { javaMailProperties.put("mail.smtp.auth", true); authenticator = new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(config.username, config.password); } }; } if ("SMTPS".equalsIgnoreCase(config.protocol)) { javaMailProperties.put("mail.smtp.ssl.enable", true); } if ("TLS".equalsIgnoreCase(config.protocol)) { javaMailProperties.put("mail.smtp.starttls.enable", true); } Session session = Session.getInstance(javaMailProperties, authenticator); session.setDebug(true); try { Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(config.sender)); for (InternetAddress internetAddress : InternetAddress.parse(config.recipients)) { msg.addRecipient(Message.RecipientType.TO, internetAddress); } msg.setSubject(config.subject); WorkflowToken token = context.getToken(); String message = config.includeWorkflowToken ? config.message + "\nUSER Workflow Tokens:\n" + token.getAll(WorkflowToken.Scope.USER) + "\nSYSTEM Workflow Tokens:\n" + token.getAll(WorkflowToken.Scope.SYSTEM) : config.message; msg.setText(message); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Transport transport = session.getTransport(config.protocol); transport.connect(config.host, config.port, config.username, config.password); try { transport.sendMessage(msg, msg.getAllRecipients()); } finally { transport.close(); } } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } } catch (Exception e) { throw new RuntimeException("Error sending email: ", e); } }

Target:
public void run(BatchActionContext context) throws Exception { if (!config.shouldRun(context)) { return; } FailureCollector collector = context.getFailureCollector(); config.validate(collector); collector.getOrThrowException(); Authenticator authenticator = null; Properties javaMailProperties = new Properties(); javaMailProperties.put("mail.smtp.host", config.host); javaMailProperties.put("mail.smtp.port", config.port); if (!(Strings.isNullOrEmpty(config.username))) { javaMailProperties.put("mail.smtp.auth", true); authenticator = new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(config.username, config.password); } }; } if ("SMTPS".equalsIgnoreCase(config.protocol)) { javaMailProperties.put("mail.smtp.ssl.enable", true); } if ("TLS".equalsIgnoreCase(config.protocol)) { javaMailProperties.put("mail.smtp.starttls.enable", true); } Session session = Session.getInstance(javaMailProperties, authenticator); session.setDebug(true); try { Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(config.sender)); for (InternetAddress internetAddress : InternetAddress.parse(config.recipients)) { msg.addRecipient(Message.RecipientType.TO, internetAddress); } msg.setSubject(config.subject); WorkflowToken token = context.getToken(); String message = config.includeWorkflowToken ? config.message + "\nUSER Workflow Tokens:\n" + token.getAll(WorkflowToken.Scope.USER) + "\nSYSTEM Workflow Tokens:\n" + token.getAll(WorkflowToken.Scope.SYSTEM) : config.message; msg.setText(message); ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Transport transport = session.getTransport(config.protocol); transport.connect(config.host, config.port, config.username, config.password); try { transport.sendMessage(msg, msg.getAllRecipients()); } finally { transport.close(); } } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } } catch (Exception e) { throw new RuntimeException("Error sending email: ", e); } }