Example usage for org.apache.commons.mail HtmlEmail HtmlEmail

List of usage examples for org.apache.commons.mail HtmlEmail HtmlEmail

Introduction

In this page you can find the example usage for org.apache.commons.mail HtmlEmail HtmlEmail.

Prototype

HtmlEmail

Source Link

Usage

From source file:com.turn.sorcerer.util.email.Emailer.java

private void sendEmail() throws EmailException, UnknownHostException {

    List<String> addresses = Lists
            .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins()));
    logger.info("Sending email to {}", addresses.toString());

    Email email = new HtmlEmail();
    email.setHostName(ADMIN_EMAIL.getHost());
    email.setSocketTimeout(30000); // 30 seconds
    email.setSocketConnectionTimeout(30000); // 30 seconds
    for (String address : addresses) {
        email.addTo(address);/*w ww  .  j av  a  2 s  .  c  om*/
    }
    email.setFrom(
            SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName());
    email.setSubject(title);
    email.setMsg(body);
    email.send();

}

From source file:com.qatickets.service.MailService.java

public void send(EmailMessage msg) throws Exception {

    HtmlEmail email = new HtmlEmail();

    email.setSmtpPort(port);//from   w  w  w  . j a  va 2s . c om
    email.setHostName(host);

    email.setHtmlMsg(msg.getHTMLContent());
    email.setTextMsg(msg.getTextContent());
    email.setSubject(msg.getSubject());

    email.addTo(msg.getRecepient().getEmail(), msg.getRecepient().getName());
    //      email.setFrom(systemOwner, "QATickets.com");

    email.send();

}

From source file:com.hangum.tadpold.commons.libs.core.mails.SendEmails.java

/**
 * send email//from w w  w  .  j  ava  2 s.  com
 * 
 * @param emailDao
 */
public void sendMail(EmailDTO emailDao) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Add new message");

    try {
        //         MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
        //         mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
        //         mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
        //         mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        //         mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
        //         mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
        //         CommandMap.setDefaultCommandMap(mc);

        HtmlEmail email = new HtmlEmail();
        email.setHostName(smtpDto.getHost());
        email.setSmtpPort(NumberUtils.toInt(smtpDto.getPort()));
        email.setAuthenticator(new DefaultAuthenticator(smtpDto.getEmail(), smtpDto.getPasswd()));
        email.setSSLOnConnect(true);

        email.setFrom(smtpDto.getEmail(), "Tadpole DB Hub");
        email.setSubject(emailDao.getSubject());

        // set the html message
        email.setHtmlMsg(emailDao.getContent());

        email.addTo(emailDao.getTo());
        email.send();

    } catch (Exception e) {
        logger.error("send email", e);
        throw e;
    }
}

From source file:io.mif.labanorodraugai.services.EmailService.java

public void sendApprovalRequestEmail(AccountApproval approval) throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    setUpHtmlEmail(email);//ww w . j a v a  2s .c o m
    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();
}

From source file:com.itcs.commons.email.impl.RunnableSendHTMLEmail.java

public void run() {
    Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO,
            "executing Asynchronous task RunnableSendHTMLEmail");
    try {//from  w  ww .jav a 2  s .co  m
        HtmlEmail email = new HtmlEmail();
        email.setCharset("utf-8");
        email.setMailSession(getSession());
        for (String dir : to) {
            email.addTo(dir);
        }
        if (cc != null) {
            for (String ccEmail : cc) {
                email.addCc(ccEmail);
            }
        }
        if (cco != null) {
            for (String ccoEmail : cco) {
                email.addBcc(ccoEmail);
            }
        }
        email.setSubject(subject);
        // set the html message
        email.setHtmlMsg(body);
        email.setFrom(getSession().getProperties().getProperty(Email.MAIL_SMTP_FROM, Email.MAIL_SMTP_USER),
                getSession().getProperties().getProperty(Email.MAIL_SMTP_FROMNAME, Email.MAIL_SMTP_USER));
        // set the alternative message
        email.setTextMsg("Si ve este mensaje, significa que su cliente de correo no permite mensajes HTML.");
        // send the email
        if (attachments != null) {
            addAttachments(email, attachments);
        }
        email.send();
        Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO,
                "Email sent successfully to:{0} cc:{1} bcc:{2}",
                new Object[] { Arrays.toString(to), Arrays.toString(cc), Arrays.toString(cco) });
    } catch (EmailException e) {
        Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.SEVERE,
                "EmailException Error sending email... with properties:\n" + session.getProperties(), e);
    }
}

From source file:com.flagleader.builder.dialogs.s.java

protected void okPressed() {
    try {//from w  w  w. j a v a  2 s .c om
        HtmlEmail localHtmlEmail = new HtmlEmail();
        localHtmlEmail.setHostName(BuilderConfig.getInstance().getEmailServer());
        localHtmlEmail.addTo("tech@flagleader.com", "VRS");
        localHtmlEmail.setAuthentication(BuilderConfig.getInstance().getEmailUser(),
                BuilderConfig.getInstance().getEmailPasswd());
        localHtmlEmail.setFrom(this.f.getText(), this.f.getText());
        localHtmlEmail.setSubject(this.c.getText() + "request rule builder license.");
        localHtmlEmail.setCharset("UTF-8");
        StringBuffer localStringBuffer = new StringBuffer();
        localStringBuffer.append("user:" + this.d.getText()).append(FileUtil.newline);
        localStringBuffer.append("mobile:" + this.e.getText()).append(FileUtil.newline);
        localStringBuffer.append("company:" + this.c.getText()).append(FileUtil.newline);
        localStringBuffer.append("checkCode:" + this.b).append(FileUtil.newline);
        localStringBuffer.append(this.a.getText());
        localHtmlEmail.setHtmlMsg(localStringBuffer.toString());
        localHtmlEmail.setMsg(localStringBuffer.toString());
        localHtmlEmail.send();
        super.okPressed();
    } catch (Exception localException) {
        MessageDialog.openError(null, "", localException.getMessage());
    }
}

From source file:com.esofthead.mycollab.module.mail.DefaultMailer.java

private HtmlEmail getBasicEmail(String fromEmail, String fromName, List<MailRecipientField> toEmail,
        List<MailRecipientField> ccEmail, List<MailRecipientField> bccEmail, String subject, String html) {
    try {/*  w ww  . j  av  a  2 s. c  om*/
        HtmlEmail email = new HtmlEmail();
        email.setHostName(host);
        email.setFrom(fromEmail, fromName);
        email.setCharset(EmailConstants.UTF_8);
        for (int i = 0; i < toEmail.size(); i++) {
            if (isValidate(toEmail.get(i).getEmail()) && isValidate(toEmail.get(i).getName())) {
                email.addTo(toEmail.get(i).getEmail(), toEmail.get(i).getName());
            } else {
                LOG.error("Invalid to email input: " + toEmail.get(i).getEmail() + "---"
                        + toEmail.get(i).getName());
            }
        }

        if (CollectionUtils.isNotEmpty(ccEmail)) {
            for (int i = 0; i < ccEmail.size(); i++) {
                if (isValidate(ccEmail.get(i).getEmail()) && isValidate(ccEmail.get(i).getName())) {
                    email.addCc(ccEmail.get(i).getEmail(), ccEmail.get(i).getName());
                } else {
                    LOG.error("Invalid cc email input: " + ccEmail.get(i).getEmail() + "---"
                            + ccEmail.get(i).getName());
                }
            }
        }

        if (CollectionUtils.isNotEmpty(bccEmail)) {
            for (int i = 0; i < bccEmail.size(); i++) {
                if (isValidate(bccEmail.get(i).getEmail()) && isValidate(bccEmail.get(i).getName())) {
                    email.addBcc(bccEmail.get(i).getEmail(), bccEmail.get(i).getName());
                } else {
                    LOG.error("Invalid bcc email input: " + bccEmail.get(i).getEmail() + "---"
                            + bccEmail.get(i).getName());
                }
            }
        }

        if (username != null) {
            email.setAuthentication(username, password);
        }
        email.setStartTLSEnabled(isTLS);
        email.setSubject(subject);

        if (StringUtils.isNotBlank(html)) {
            email.setHtmlMsg(html);
        }

        return email;
    } catch (EmailException e) {
        throw new MyCollabException(e);
    }
}

From source file:br.com.itfox.utils.SendHtmlFormatedEmail.java

public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) {
    try {/*from www .  j a  v  a  2  s  . co m*/
        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("belchiorpalma@gmail.com", "xp2002b5"));
        email.setSSLOnConnect(true);
        email.setTLS(true);
        email.setFrom("contato@itfox.com.br");
        //email.setSubject("TestMail");
        email.addTo(toEmail, toName);
        //email.setFrom("belchiorpalma@me.com", "Me");
        //email.setSubject("Test email with inline image");
        email.setSubject(MimeUtility.encodeText("Thank you for your order", "UTF-8", "B"));

        // embed the image and get the content id
        //URL url = new URL("http://boutiquecellars.com/img/white-wines.jpg");
        //String cid = email.embed(url, "BoutiqueCellars.com");

        // set the html message
        email.setHtmlMsg("Thank you for your order\n<br/><br/>" + "\n" + "We received your order #"
                + orderNumber + " and we are working on it now.\n<br/>"
                + "We will e-mail you an update as soon as your order is processed.\n<br/>" + "\n<br/>"
                + "Boutique Cellars team\n"
                + "\n<br/><br/><img src='http://boutiquecellars.com/img/logoemail.jpg'/> \n" +
                //orderDetails +
                "<br/><br/>BOUTIQUE CELLARS SUPPORTS THE RESPONSIBLE SERVICE OF ALCOHOL. NSW: UNDER THE LIQUOR\n<br/>"
                + "ACT 2007 IT IS AGAINST THE LAW TO SELL OR SUPPLY ALCOHOL TO, OR TO OBTAIN ALCOHOL ON\n<br/>"
                + "BEHALF OF, A PERSON UNDER THE AGE OF 18 YEARS. NSW PACKAGED LIQUOR LICENCE NUMBER\n<br/>"
                + "LIQP770016947. YOUR CONTRACT OF SALE IS WITH THE RELEVANT LICENSEE AT THE RELEVANT\n<br/>"
                + "PREMISES FROM WHICH YOU ORDER IS ACCEPTED AND FULFILLED. LIQUOR IS SOLD FROM OUR\n<br/>"
                + "PLATFORM ON BEHALF OF THE RELEVANT LICENSEE. ACCORDINGLY, YOUR OFFER TO PURCHASE IS\n<br/>"
                + "SUBJECT TO ACCEPTANCE OF YOUR OFFER BY THE HOLDER OF THE LIQUOR LICENCE, CERTIFICATION\n<br/>"
                + "AND EVIDENCE OF YOU BEING OVER 18 YEARS OF AGE, THE AVAILABILITY OF STOCK AND THE\n<br/>"
                + "LIQUOR WHICH IS THE SUBJECT MATTER OF YOUR OFFER BEING ASCERTAINED AND APPROPRIATED\n<br/>"
                + "AT THE ABOVE MENTIONED LICENSED PREMISES.<br/><br/>"
                + " Boutique Cellar Imports Pty Ltd | ABN 69 607 265 618");

        // set the alternative message
        email.setTextMsg(
                "Thank you for your order, We received your order #18765 and we are working on it now.\n"
                        + "We will e-mail you an update as soon as your order is processed.\n" + "\n"
                        + "Boutique Cellars team");

        // send the email
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }
    /*} catch (MalformedURLException ex) {
     Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }*/

}

From source file:com.github.robozonky.notifications.EmailHandler.java

private HtmlEmail createNewEmail(final SessionInfo session) throws EmailException {
    final HtmlEmail email = new HtmlEmail();
    email.setCharset(Defaults.CHARSET.displayName()); // otherwise the e-mail contents are mangled
    email.setHostName(getSmtpHostname());
    email.setSmtpPort(getSmtpPort());//www.  j  a v  a  2  s  .c o  m
    email.setStartTLSRequired(isStartTlsRequired());
    email.setSSLOnConnect(isSslOnConnectRequired());
    if (isAuthenticationRequired()) {
        final String username = getSmtpUsername();
        LOGGER.debug("Will contact SMTP server as '{}'.", username);
        email.setAuthentication(getSmtpUsername(), getSmtpPassword());
    } else {
        LOGGER.debug("Will contact SMTP server anonymously.");
    }
    email.setFrom(getSender(), session.getName());
    email.addTo(getRecipient());
    return email;
}

From source file:com.dattack.jtoolbox.commons.email.HtmlEmailBuilder.java

/**
 * Builder method./*w w  w.  j  av a  2s  . c o m*/
 *
 * @return the HtmlEmail
 * @throws EmailException
 *             if an error occurs while creating the email
 */
public HtmlEmail build() throws EmailException {

    if (hostname == null || hostname.isEmpty()) {
        throw new EmailException(String.format("Invalid SMTP server (hostname: '%s')", hostname));
    }

    if (from == null || from.isEmpty()) {
        throw new EmailException(String.format("Invalid email address (FROM: '%s'", from));
    }

    final HtmlEmail email = new HtmlEmail();
    email.setHostName(hostname);
    email.setFrom(from);
    email.setSubject(subject);

    if (message != null && !message.isEmpty()) {
        email.setMsg(message);
    }

    if (port > 0) {
        email.setSmtpPort(port);
    }

    if (username != null && !username.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(username, password));
    }

    if (sslOnConnect != null) {
        email.setSSLOnConnect(sslOnConnect);
    }

    if (startTlsEnabled != null) {
        email.setStartTLSEnabled(startTlsEnabled);
    }

    if (!toList.isEmpty()) {
        email.setTo(toList);
    }

    if (!ccList.isEmpty()) {
        email.setCc(ccList);
    }

    if (!bccList.isEmpty()) {
        email.setBcc(bccList);
    }
    return email;
}