List of usage examples for org.apache.commons.mail Email setAuthenticator
public void setAuthenticator(final Authenticator newAuthenticator)
Authenticator
to be used when authentication is requested from the mail server. From source file:com.esofthead.mycollab.servlet.EmailValidationServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String smtpUserName = request.getParameter("smtpUserName"); String smtpPassword = request.getParameter("smtpPassword"); String smtpHost = request.getParameter("smtpHost"); String smtpPort = request.getParameter("smtpPort"); String tls = request.getParameter("tls"); int mailServerPort; try {/*from www . ja va2 s .com*/ mailServerPort = Integer.parseInt(smtpPort); } catch (Exception e) { PrintWriter out = response.getWriter(); out.write("Port must be an integer value"); return; } try { Email email = new SimpleEmail(); email.setHostName(smtpHost); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword)); if (tls.equals("true")) { email.setSSLOnConnect(true); } else { email.setSSLOnConnect(false); } email.setFrom(smtpUserName); email.setSubject("MyCollab Test Email"); email.setMsg("This is a test mail ... :-)"); email.addTo(smtpUserName); email.send(); } catch (EmailException e) { PrintWriter out = response.getWriter(); out.write("Cannot establish SMTP connection. Please recheck your config."); return; } }
From source file:net.sasasin.sreader.batch.publish.GMailPublisher.java
@Override public void publish(ContentViewId content) { try {/*from w w w . ja va2 s.c o m*/ Email email = new SimpleEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setStartTLSEnabled(true); email.setCharset("UTF-8"); email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword())); email.setFrom(content.getEmail()); email.addTo(content.getEmail()); email.setSubject(content.getTitle()); email.setMsg(content.getUrl() + "\n" + content.getFullText()); email.send(); log(content); } catch (EmailException e) { e.printStackTrace(); } }
From source file:com.mycollab.servlet.EmailValidationServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String smtpUserName = request.getParameter("smtpUserName"); String smtpPassword = request.getParameter("smtpPassword"); String smtpHost = request.getParameter("smtpHost"); String smtpPort = request.getParameter("smtpPort"); String tls = request.getParameter("tls"); String ssl = request.getParameter("ssl"); int mailServerPort = 25; try {/*from ww w . j a va 2 s.c o m*/ mailServerPort = Integer.parseInt(smtpPort); } catch (Exception e) { LOG.info("The smtp port value is not a number. We will use default port value is 25"); } try { Email email = new SimpleEmail(); email.setHostName(smtpHost); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword)); if ("true".equals(tls)) { email.setStartTLSEnabled(true); } else { email.setStartTLSEnabled(false); } if ("true".equals(ssl)) { email.setSSLOnConnect(true); } else { email.setSSLOnConnect(false); } email.setFrom(smtpUserName); email.setSubject("MyCollab Test Email"); email.setMsg("This is a test mail ... :-)"); email.addTo(smtpUserName); email.send(); } catch (EmailException e) { PrintWriter out = response.getWriter(); out.write("Cannot establish SMTP connection. Please recheck your config."); LOG.warn("Can not login to SMTP", e); } }
From source file:com.projetIF4.controller.MailControleur.java
public void mail() throws EmailException { Email email = new SimpleEmail(); email.setCharset("UTF-8"); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465);/*from w w w. j av a 2s .c o m*/ email.setAuthenticator(new DefaultAuthenticator("fst.rnu.info@gmail.com", "adminFST123456789")); email.setSSLOnConnect(true); email.setFrom("fst.rnu.info@gmail.com", "Dpartement Informatique FST"); email.setSubject(objet); email.setMsg(message); email.addTo(mailDestination); email.send(); }
From source file:at.treedb.util.Mail.java
/** * /*from w w w. j av a 2 s .co m*/ * @param sendTo * @param subject * @param message * @throws EmailException */ public void sendMail(String mailTo, String mailFrom, String subject, String message) throws Exception { Objects.requireNonNull(mailTo, "Mail.sendMail(): mailTo can not be null!"); Objects.requireNonNull(mailFrom, "Mail.sendMail(): mailFrom can not be null!"); Objects.requireNonNull(subject, "Mail.sendMail(): subject can not be null!"); Objects.requireNonNull(message, "Mail.sendMail(): message can not be null!"); Email email = new SimpleEmail(); email.setHostName(smtpHost); email.setAuthenticator(new DefaultAuthenticator(smtpUser, smtpPassword)); if (transportSecurity == TransportSecurity.SSL) { email.setSSLOnConnect(true); email.setSSLCheckServerIdentity(false); } else if (transportSecurity == TransportSecurity.STARTTLS) { email.setStartTLSRequired(true); } email.setSmtpPort(smtpPort); email.setFrom(mailFrom); email.setSubject(subject); email.setMsg(message); email.addTo(mailTo); email.send(); }
From source file:FacultyAdvisement.ImagineBean.java
public String submitRequest() { String emailCourses = ""; for (Course c : currentCourses) { emailCourses += "<li>" + c.getSubject() + " " + c.getNumber() + "</li>"; }//from w w w .ja va2 s. co m try { Email email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234")); email.setSSLOnConnect(true); email.setFrom("uco.faculty.advisement@gmail.com"); email.setSubject("Microsoft Imagine Account"); email.setMsg("<font size=\"3\" style=\"font-family:verdana\"> \n" + "<ul><li>Student Name: " + student.getFirstName() + " " + student.getLastName() + "</li><li>Student Major: " + student.getMajorCode() + "<li>Current Courses: <ol>" + emailCourses + "</ol></li></ul> " + "Student Email if needed for response: " + student.getUsername() + "\n<p align=\"center\">UCO Faculty Advisement</p></font>"); email.addTo("uco.faculty.advisement@gmail.com"); email.send(); } catch (EmailException ex) { Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex); } return "/customerFolder/imagineConfirm"; }
From source file:com.github.frapontillo.pulse.email.EmailNotifier.java
/** * Send an email, using the provided parameters, notifying if the pipeline succeeded or errored. * * @param parameters The {@link EmailNotifierConfig} to use. * @param isSuccess {@code true} to report a success, {@code false} to report an error. *//* w w w . j a v a2 s . c o m*/ private void sendEmail(EmailNotifierConfig parameters, boolean isSuccess) { if (parameters.getAddresses() == null || parameters.getAddresses().length == 0) { return; } try { Email email = new SimpleEmail(); email.setHostName(parameters.getHost()); email.setSmtpPort(parameters.getPort()); email.setAuthenticator(new DefaultAuthenticator(parameters.getUsername(), parameters.getPassword())); email.setSSLOnConnect(parameters.getUseSsl()); email.setFrom(parameters.getFrom()); email.setSubject(parameters.getSubject()); String body; if (isSuccess) { body = parameters.getBodySuccess(); } else { body = parameters.getBodyError(); } body = body.replace("{{NAME}}", getProcessInfo().getName()); email.setMsg(body); email.addTo(parameters.getAddresses()); email.send(); } catch (EmailException e) { logger.error(e); e.printStackTrace(); } }
From source file:ch.fihlon.moodini.business.token.control.TokenService.java
@SneakyThrows private void sendChallenge(@NotNull final String email, @NotNull final Challenge challenge) { final SmtpConfiguration smtp = configuration.getSmtp(); final Email mail = new SimpleEmail(); mail.setHostName(smtp.getHostname()); mail.setSmtpPort(smtp.getPort());/*from w ww. j a va2s. com*/ mail.setAuthenticator(new DefaultAuthenticator(smtp.getUser(), smtp.getPassword())); mail.setSSLOnConnect(smtp.getSsl()); mail.setFrom(smtp.getFrom()); mail.setSubject("Your challenge to login to Moodini"); mail.setMsg(String.format("Your one time challenge, valid for 10 minutes: %s", challenge.getChallenge())); mail.addTo(email); mail.send(); }
From source file:com.basetechnology.s0.agentserver.mail.AgentMail.java
public int sendMessage(User user, String toEmail, String toName, String subject, String message, String messageTrailer1, String messageTrailer2) throws AgentServerException { try {// w w w . j a v a2 s. c o m // Wait until we have mail access agentServer.mailAccessManager.wait(user, toEmail); int messageId = ++nextMessageId; log.info("Sending mail on behalf of user " + user.id + " with message Id " + messageId + " To: '<" + toName + ">" + toEmail + "' Subject: '" + subject + "'"); Email email = new SimpleEmail(); email.setDebug(debug); email.setHostName(mailServerHostName); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(mailServerUserName, mailServerUserPassword)); email.setTLS(true); email.setFrom(mailServerFromEmail, mailServerFromName); // TODO: Reconsider whether we want to always mess with subject line email.setSubject(subject + " (#" + messageId + ")"); email.setMsg(message + messageTrailer1 + (messageTrailer2 != null ? messageId + messageTrailer2 : "")); email.addTo(toEmail, toName); email.send(); log.info("Message sent"); // Return the message Id return messageId; } catch (EmailException e) { e.printStackTrace(); throw new AgentServerException("EmailException sending email - " + e.getMessage()); } }
From source file:edu.corgi.uco.sendEmails.java
public void sendConfirmation(String email2, String firstName, String lastName, int token, int id) throws EmailException { Email email = new SimpleEmail(); email.setDebug(true);/*ww w . j a va2s . co m*/ email.setHostName("smtp.gmail.com"); email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung")); email.setStartTLSEnabled(true); email.setSmtpPort(587); email.setFrom("ucocorgi@gmail.com", "UCO CS Corgi"); email.setSubject("Account Confirmation"); email.setMsg(firstName + " " + lastName + " please go to the following address http://localhost:8080/Corgi/faces/accountAuth.xhtml " + "and enter the token:" + token + " and the ID:" + id + " to confirm and activate your account"); System.out.print("Email Address: " + email2); email.addTo(email2); email.send(); }