package api;
import org.apache.commons.mail.*;



public class EmailNotification {
	public static class EmailSmtpInformation{

		public String hostName;
		public int port;
		
		public String username;
		public String password;
		public String fromEmail;
		public String toEmail;
	}
	
	
	
	
	public static void main(String[] args) {
		System.out.println("hello");
		
		EmailSmtpInformation info = new EmailSmtpInformation();
		info.hostName = "smtp.googlemail.com";
		info.port = 465;
		info.username = "holeg.nuc.notification";
		info.password = "";
		info.fromEmail = "holeg.nuc.notification@gmail.com";
		info.toEmail = "";
		String subject = "TestMail123";
		String message = "This is a test mail ... :-)";
		sendEmail(info, subject, message);
	}




	private static void sendEmail(EmailSmtpInformation info, String subject, String message) {
		Email email = new SimpleEmail();
		email.setHostName(info.hostName);
		email.setSmtpPort(info.port);
		System.out.println(info.username);
		email.setAuthenticator(new DefaultAuthenticator(info.username, info.password));
		email.setSSLOnConnect(true);
		email.setSubject(subject);
		try {
			email.setFrom(info.fromEmail);
			email.setMsg(message);
			email.addTo(info.toEmail);
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
}
