List of usage examples for org.apache.commons.mail Email send
public String send() throws EmailException
From source file:com.kylinolap.common.util.MailService.java
/** * // w ww .j av a 2 s . c o m * @param receivers * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content) throws IOException { if (!enabled) { logger.info("Email service is disabled; this mail will not be delivered: " + subject); logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties"); return false; } Email email = new HtmlEmail(); email.setHostName(host); if (username != null && username.trim().length() > 0) { email.setAuthentication(username, password); } //email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); } catch (EmailException e) { logger.error(e.getLocalizedMessage(), e); return false; } return true; }
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());// w w w .j a v a2 s. c o m 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.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 w w w. j ava 2 s . c om 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:in.flipbrain.controllers.BaseController.java
protected void sendEmail(String to, String subject, String body) throws EmailException { logger.debug("Sending email to " + to + "\nSubject: " + subject + "\nMessage: " + body); if ("true".equalsIgnoreCase(getConfigValue(Constants.EM_FAKE_SEND))) return;//www .j a va 2 s . c o m Email email = new SimpleEmail(); email.setHostName(getConfigValue("smtp.host")); email.setSmtpPort(Integer.parseUnsignedInt(getConfigValue("smtp.port"))); email.setAuthenticator( new DefaultAuthenticator(getConfigValue("smtp.user"), getConfigValue("smtp.password"))); email.setSSLOnConnect(Boolean.parseBoolean(getConfigValue("smtp.ssl"))); email.setFrom(getConfigValue("smtp.sender")); email.setSubject(subject); email.setMsg(body); email.addTo(to); email.send(); }
From source file:com.patrolpro.beans.ContactUsBean.java
public String sendEmail() { try {//from w w w.j a v a2 s . c o m StringBuilder emailMessage = new StringBuilder(); emailMessage.append("From: " + this.name + "\r\n"); emailMessage.append("Email: " + this.email + "\r\n"); emailMessage.append("Phone: " + this.phone + "\r\n"); emailMessage.append(message); Email htmlEmail = new SimpleEmail(); htmlEmail.setMsg(message); htmlEmail.setFrom("contact@patrolpro.com"); htmlEmail.setSubject("Contact Us Email"); htmlEmail.addTo("rharris@ainteractivesolution.com"); htmlEmail.addCc("ijuneau@ainteractivesolution.com"); htmlEmail.addCc("jc@champ.net"); htmlEmail.setMsg(emailMessage.toString()); htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3")); htmlEmail.setHostName("mail2.champ.net"); htmlEmail.setSmtpPort(587); htmlEmail.send(); return "sentContactEmail"; } catch (Exception exe) { } return "invalid"; }
From source file:com.swissbit.ifttt.IFTTTConfgurationImpl.java
/** {@inheritDoc} */ @Override/*from w ww.j a va 2s . co m*/ public void trigger() { LOGGER.debug("IFTTT Email is getting sent..."); final List<String> tags = this.retrieveHashtags(this.m_hashTags); if (tags.size() == 0) { return; } if (tags.size() > 0) { for (final String tag : tags) { try { final Email email = new SimpleEmail(); email.setHostName(this.m_smtpHost); email.setSmtpPort(this.m_smtpPort); email.setAuthenticator(new DefaultAuthenticator(this.m_smtpUsername, this.m_smtpPassword)); email.setSSL(true); email.setFrom(this.m_smtpUsername); email.setSubject(tag); email.setMsg("This is a test mail ... :-)"); email.addTo(TRIGGER_EMAIL); email.send(); } catch (final EmailException e) { LOGGER.error(Throwables.getStackTraceAsString(e)); } } } LOGGER.debug("IFTTT Email is sent...Done"); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Sends a password reset email to the email address provided * //from ww w. ja v a2 s . co m * @param toEmail * @param newPwd * @throws Exception */ public void sendPwdResetMailFromApp(String toEmail, String newPwd) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Reset Olhie Password"); email.setMsg("You have requested that your password be reset. Your new Olhie password is " + newPwd); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Author Request email that goes to the olhie administrator * /*from w w w .jav a 2 s. co m*/ * @param toEmail * @param userId * @param firstName * @param lastName * @param regId * @throws Exception */ public void sendRequestAuthorMailFromApp(String toEmail, String userId, String firstName, String lastName, String regId) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Author Request"); email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Registration Id: " + regId); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.waveerp.sendMail.java
public void sendMsg(String strSource, String strSourceDesc, String strSubject, String strMsg, String strDestination, String strDestDesc) throws Exception { // Call the registry management system registrySystem rs = new registrySystem(); // Call the encryption management system desEncryption de = new desEncryption(); de.Encrypter("", ""); String strHost = rs.readRegistry("NA", "NA", "NA", "EMAILHOST"); String strPort = rs.readRegistry("NA", "NA", "NA", "EMAILPORT"); String strUser = rs.readRegistry("NA", "NA", "NA", "EMAILUSER"); String strPass = rs.readRegistry("NA", "NA", "NA", "EMAILPASSWORD"); log(DEBUG, strHost + "|" + strPort + "|" + strUser + "|" + strPass); //Decrypt the encrypted password. strPass = de.decrypt(strPass);/*from www . j av a 2 s. com*/ Email email = new SimpleEmail(); email.setHostName(strHost); email.setSmtpPort(Integer.parseInt(strPort)); email.setAuthenticator(new DefaultAuthenticator(strUser, strPass)); email.setTLS(false); email.setFrom(strSource, strSourceDesc); email.setSubject(strSubject); email.setMsg(strMsg); email.addTo(strDestination, strDestDesc); email.send(); }
From source file:at.treedb.util.Mail.java
/** * // ww w. j a va 2s. c o 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(); }