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

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

Introduction

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

Prototype

public void setHostName(final String aHostName) 

Source Link

Document

Set the hostname of the outgoing mail server.

Usage

From source file:ca.ualberta.physics.cssdp.auth.service.EmailServiceImpl.java

public void sendEmail(String from, String to, String subject, String body) {

    try {//from  ww w .  j a  va 2  s .  c  om

        String host = AuthServer.properties().getString("smtpHost");
        int port = AuthServer.properties().getInt("smtpPort");
        final String user = AuthServer.properties().getString("smtpUsername");
        final String password = AuthServer.properties().getString("smtpPassword");
        String systemEmail = AuthServer.properties().getString("systemEmailAddress");
        boolean useSSL = AuthServer.properties().getBoolean("smtpUseSSL");
        boolean debug = AuthServer.properties().getBoolean("smtpDebug");

        HtmlEmail msg = new HtmlEmail();
        msg.setHostName(host);
        msg.setAuthentication(user, password);
        msg.setSmtpPort(port);
        msg.setSSL(useSSL);
        msg.setDebug(debug);
        msg.setSubject("Password Reset Request");
        msg.addTo(to);
        msg.setFrom(systemEmail);
        msg.setHtmlMsg(body);
        msg.send();

    } catch (Exception e) {
        e.printStackTrace();
        throw Throwables.propagate(Throwables.getRootCause(e));
    } finally {
    }

}

From source file:be.thomasmore.controller.EmailController.java

public String sendEmail() throws EmailException {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();//from   ww w  .j a  v a 2 s . c om
    String id = params.get("studentId");
    int studentId = Integer.parseInt(id);
    Student student = service.getStudent(studentId);
    HtmlEmail email = new HtmlEmail();

    email.setHostName("smtp.gmail.com");
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("pointernulltest@gmail.com", "r0449914"));
    email.setSSLOnConnect(true);
    email.addTo(student.getEmail(), student.getNaam() + " " + student.getVoornaam());
    email.setFrom("me@apache.org", "Thomas More Geel");
    email.setSubject("Rapport");
    StringBuffer msg = new StringBuffer();
    msg.append("<html><body>");
    msg.append("<h2>Resultaten</h2>");
    List<Score> scores = student.getScoreList();
    msg.append("<p>Beste " + student.getVoornaam() + " " + student.getNaam()
            + " hieronder vind je je punten voor afgelopen semester.");
    for (Score score : scores) {
        msg.append("<p>");
        msg.append(score.getTestId().getVakId().getNaam() + " " + score.getTestId().getBeschrijving() + " : "
                + score.getScore());
        msg.append("</p>");
        msg.append("</body></html>");
    }
    email.setHtmlMsg(msg.toString());

    email.send();
    return null;
}

From source file:br.vn.Model.Filtros.Email.java

public void enviarHatml(String emailcliente) throws MalformedURLException {

    try {//  w w  w  .j  a v a  2s. c  o m
        // Criar a mensagem de e-mail
        HtmlEmail email = new HtmlEmail();
        email.setHostName("org.apache.commons");

        email.addTo("jdoe@somewhere.org", "John Doe");
        email.setFrom("me@apache.org", "Me");
        email.setSubject("Test email with inline image");

        //incorporar a imagem e obter o ID de contedo
        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
        String cid = email.embed(url, "Apache logo");

        // definir a mensagem HTML
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");

        // definir a mensagem alternativa
        email.setTextMsg("Your email client does not support HTML messages");

        // enviar o e-mail
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:dk.dma.ais.abnormal.analyzer.reports.ReportMailer.java

/**
 * Send email with subject and message body.
 * @param subject the email subject.//from w  w w. j a va2 s . c  o m
 * @param body the email body.
 */
public void send(String subject, String body) {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_HOST, "localhost"));
        email.setSmtpPort(configuration.getInt(CONFKEY_REPORTS_MAILER_SMTP_PORT, 465));
        email.setAuthenticator(
                new DefaultAuthenticator(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_USER, "anonymous"),
                        configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_PASS, "guest")));
        email.setStartTLSEnabled(false);
        email.setSSLOnConnect(configuration.getBoolean(CONFKEY_REPORTS_MAILER_SMTP_SSL, true));
        email.setFrom(configuration.getString(CONFKEY_REPORTS_MAILER_SMTP_FROM, ""));
        email.setSubject(subject);
        email.setHtmlMsg(body);
        String[] receivers = configuration.getStringArray(CONFKEY_REPORTS_MAILER_SMTP_TO);
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        email.send();
        LOG.info("Report sent with email to " + email.getToAddresses().toString() + " (\"" + subject + "\")");
    } catch (EmailException e) {
        LOG.error(e.getMessage(), e);
    }
}

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

/**
 * send email/*from  w w w.  jav a2  s  . c o m*/
 * 
 * @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:com.flagleader.builder.dialogs.s.java

protected void okPressed() {
    try {/*from w w w  .  ja  v a  2s . co m*/
        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:br.com.atmatech.sac.controller.Email.java

public void emai(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls,
        String emailto, String emailfrom, String conteudo, String assunto)
        throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(smtp); // o servidor SMTP para envio do e-mail                  
    email.addTo(emailto);//destinatario            
    conteudo = conteudo.replaceAll("\n", "<p>");
    email.setFrom(emailfrom); // remetente        
    //email.addCc(emailfrom);
    email.setSubject(assunto);// w ww . j ava 2s  . co m
    // configura a mensagem para o formato HTML        
    email.setHtmlMsg("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
            + conteudo + "</html>");
    email.setAuthentication(user, password);
    email.setSmtpPort(porta);
    email.setSSL(ssl);
    email.setTLS(tls);
    email.send();
}

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

public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) {
    try {/* w  ww  . j a v  a  2  s . c o  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.cerebro.gorgone.commons.SendConfEmail.java

public SendConfEmail(String address, String confCode) {

    logger.info("Invio della mail di conferma");
    // Leggo i parametri di invio
    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        try {/*from w w  w . j  a va  2 s . c  o  m*/
            logger.info("Carico il file .properties");
            props.load(config);
        } catch (Exception ex) {
            logger.error("Errore nel caricamento del file .properties: " + ex.getMessage());
        }
    }
    smtp_host = props.getProperty(ConfigProperties.SMTP_HOST);
    smtp_port = Integer.getInteger(props.getProperty(ConfigProperties.SMTP_PORT));
    smtp_user = props.getProperty(ConfigProperties.SMTP_USER);
    smtp_pwd = props.getProperty(ConfigProperties.SMTP_PWD);
    smtp_security = Boolean.parseBoolean(ConfigProperties.SMTP_SECURITY);
    // Creo la mail
    HtmlEmail email = new HtmlEmail();
    try {
        email.setHostName(smtp_host);
        email.setSmtpPort(smtp_port);
        email.setSSLOnConnect(smtp_security);
        email.setAuthentication(smtp_user, smtp_pwd);
        email.setFrom("gioco@gioco.com", "Gioco");
        email.setSubject("Conferma il tuo indirizzo email " + confCode);
        email.addTo(address);
        email.setMsg("Messaggio della mail");
        email.send();
        logger.info("Email inviata");
    } catch (EmailException ex) {
        logger.error("Errore nell'invio della mail");
        logger.error(ex.getMessage());
    }
}

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

public void send(EmailMessage msg) throws Exception {

    HtmlEmail email = new HtmlEmail();

    email.setSmtpPort(port);/* w  w  w.  j a  va  2  s.  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();

}