package org.ihtsdo.commons.email;

import java.net.MalformedURLException;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class EmailSender {

	private final String smtpHost;
	private final int smtpPort;
	private final String smtpUsername;
	private final String smtpPassword;
	private final boolean smtpSsl;

	public EmailSender(final String smtpHost, final int smtpPort, final String smtpUsername, final String smtpPassword,
			final boolean smtpSsl) {
		this.smtpHost = smtpHost;
		this.smtpPort = smtpPort;
		this.smtpUsername = smtpUsername;
		this.smtpPassword = smtpPassword;
		this.smtpSsl = smtpSsl;
	}

	public void send(EmailRequest request) throws EmailException, MalformedURLException {

		SimpleEmail email = new SimpleEmail();
		email.setFrom(request.getFromEmail(), request.getFromName());
		email.setSubject(request.getSubject());
		email.addTo(request.getToEmail());
		email.setMsg(request.getTextBody());

		addStandardDetails(email);
		email.send();
	}

	private void addStandardDetails(Email email) throws EmailException {
		email.setHostName(smtpHost);
		email.setSmtpPort(smtpPort);
		email.setAuthenticator(new DefaultAuthenticator(smtpUsername, smtpPassword));
		email.setSSLOnConnect(smtpSsl);
		// If we're using SSL, then the port specified will be the port to use for sSmtp also
		if (smtpSsl) {
			email.setSslSmtpPort(Integer.toString(smtpPort));
		}
	}

	public String toString() {
		return smtpUsername + " via " + smtpHost + ":" + smtpPort + (smtpSsl ? " with ssl" : " without ssl");
	}
}

@@ -989,79 +989,355 @@
 ;%0A%09%09
+// Split multiple 
 email
-.addTo(request.getToEmail());%0A%09%09email.setMsg(request.getTextBody()
+ addresses on either comma or semicolon%0A%09%09String%5B%5D toAddresses = request.getToEmail().split(%22,%7C;%22);%0A%09%09for (String thisToAddress : toAddresses) %7B%0A%09%09%09email.addTo(thisToAddress);%0A%09%09%7D%0A%09%09email.setMsg(request.getTextBody());%0A%0A%09%09// Send email to multiple recipients even if one email address is invalid.%0A%09%09email.setSendPartial(true
 );%0A%0A

Add support for sending telemetry alerts to multiple email addresses.