private void setCommonConfigElements(Email email, String toName, String toEmail, String subject, Map<String, String> headers)
         throws org.apache.commons.mail.EmailException {
        email.setCharset(EmailConstants.UTF_8);
        email.addTo(toEmail, toName);
        email.setFrom(emailConfiguration.getFromEmail(), emailConfiguration.getFromName());
        email.setSubject(subject);
        email.setHostName(emailConfiguration.getHost());
        email.setSmtpPort(emailConfiguration.getPort());
        email.setAuthenticator(new DefaultAuthenticator(emailConfiguration.getUsername(), emailConfiguration.getPassword()));
        email.getHeaders().putAll(headers);

        if (emailConfiguration.getStartTLSMode() == StartTLSEnum.REQUIRED || emailConfiguration.getStartTLSMode() == StartTLSEnum.OPTIONAL) {
            email.setStartTLSEnabled(true);
            if (emailConfiguration.getStartTLSMode() == StartTLSEnum.REQUIRED) {
                // https://issues.apache.org/jira/browse/EMAIL-105
                // mail.smtp.starttls.required in addition to mail.smtp.starttls.enable, to make the client disconnect if the server doesn't support STARTTLS.
                email.setStartTLSRequired(true);
            }
        } else if (emailConfiguration.getStartTLSMode() == StartTLSEnum.DISABLED) {
            email.setStartTLSRequired(false);
        }
        if (emailConfiguration.isSsl()) {
            email.setSslSmtpPort(Integer.toString(emailConfiguration.getPort()));
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
    }
@author Marc Savy {@literal <marc@blackparrotlabs.io>}
manager/api/rest-impl/src/main/java/io/apiman/manager/api/notifications/email/EmailSender.java