package com.battleweb.tools;


import java.util.Properties;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 * @author Lukashchuk Ivan
 * 
 */
@Stateless
@LocalBean
public class ToolEmail {
	
	 	private String username;
	    private String password;
	    private Properties props;
	 
	   {
	        this.username = "battleofrotterdam@gmail.com";
	        this.password = "battleofrotterdam2014";
	 
	        props = new Properties();
	        props.put("mail.smtp.auth", "true");
	        props.put("mail.smtp.starttls.enable", "true");
	        props.put("mail.smtp.host", "smtp.gmail.com");
	        props.put("mail.smtp.port", "587");
	    }
	 
	    public void send(String subject, String text, String fromEmail, String toEmail){
	        Session session = Session.getInstance(props, new Authenticator() {
	            protected PasswordAuthentication getPasswordAuthentication() {
	                return new PasswordAuthentication(username, password);
	            }
	        });
	 
	        try {
	            Message message = new MimeMessage(session);
	            message.setFrom(new InternetAddress(username));
	            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail));
	            message.setSubject(subject);
	            message.setText(text);
	 
	            Transport.send(message);
	        } catch (MessagingException e) {
	            throw new RuntimeException(e);
	        }
	    }
	
}

@@ -128,17 +128,29 @@
 ax.mail.
-*
+Authenticator
 ;%0Aimport
@@ -153,32 +153,195 @@
 port javax.mail.
+Message;%0Aimport javax.mail.MessagingException;%0Aimport javax.mail.PasswordAuthentication;%0Aimport javax.mail.Session;%0Aimport javax.mail.Transport;%0Aimport javax.mail.
 internet.Interne
@@ -392,65 +392,8 @@
 sage
-;%0A%0Aimport javax.ejb.LocalBean;%0Aimport javax.ejb.Stateless
 ;%0A%0A/

Update tool