Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package io.mif.labanorodraugai.services; import io.mif.labanorodraugai.entities.AccountApproval; import io.mif.labanorodraugai.entities.Account; import java.net.MalformedURLException; import javax.ejb.Stateless; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.EmailConstants; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; /** * * @author Vytautas */ @Stateless public class EmailService { public void SendInvitationEmail(Account sender, String toEmail) throws EmailException, MalformedURLException { //ImageHtmlEmail email = new ImageHtmlEmail(); HtmlEmail email = new HtmlEmail(); setUpHtmlEmail(email); email.addTo(toEmail); email.setSubject("Labanoro draug kvietimas"); StringBuilder msg = new StringBuilder(); //msg.append("<div><img src=\"" + baseUrl + "/images/lab anorodraugai.JPG\"></div>"); msg.append("<h4>Sveiki,</h4>"); msg.append("<p>" + sender.getName() + " " + sender.getLastname() + " kvie?ia Jus tapti bendrijos Labanoro draugai nariu!</p>"); msg.append("<p>T padaryti galite usiregistrav "); msg.append("<a href=" + "\"http://localhost:8080/LabanoroDraugai/registration/registration.html\">"); msg.append("?ia</a></p>"); email.setContent(msg.toString(), EmailConstants.TEXT_HTML); email.send(); } private void setUpHtmlEmail(HtmlEmail email) throws EmailException { email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("labanorodraugaibendrija@gmail.com", "labanoro123")); email.setSSLOnConnect(true); email.setCharset("UTF-8"); email.setFrom("labanorodraugaibendrija@gmail.com", "Labanoro draugai"); } public void sendApprovalRequestEmail(AccountApproval approval) throws EmailException, MalformedURLException { HtmlEmail email = new HtmlEmail(); setUpHtmlEmail(email); email.addTo(approval.getApprover().getEmail()); email.setSubject("Naujo nario rekomendacija"); Account candidate = approval.getCandidate(); StringBuilder msg = new StringBuilder(); //msg.append("<div><img src=\"" + baseUrl + "/images/lab anorodraugai.JPG\"></div>"); msg.append("<h4>Sveiki,</h4>"); msg.append("<p>" + candidate.getName() + " " + candidate.getLastname() + " (" + candidate.getEmail() + ") nori tapti Labanoro Draugai nariu ir prao Js suteikti rekomendacij!</p>"); msg.append("<p>T padaryti galite: "); msg.append("<a href=" + "\"http://localhost:8080/LabanoroDraugai/registration/approval.html?gen=" + approval.getGeneratedId() + "\">"); msg.append("?ia</a></p>"); email.setContent(msg.toString(), EmailConstants.TEXT_HTML); email.send(); } }