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

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

Introduction

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

Prototype

public void setSmtpPort(final int aPortNumber) 

Source Link

Document

Set the port number of the outgoing mail server.

Usage

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

/**
 * send email/*from  w ww.  j ava 2 s  .  co  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.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 {//  w  w w. ja  v a 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:br.com.itfox.utils.SendHtmlFormatedEmail.java

public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) {
    try {//from  ww  w  . ja  v a2 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:ca.ualberta.physics.cssdp.auth.service.EmailServiceImpl.java

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

    try {/* ww w.  j  a v a2 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:dk.dma.ais.abnormal.analyzer.reports.ReportMailer.java

/**
 * Send email with subject and message body.
 * @param subject the email subject./*from w  ww  . jav a  2s  .c  om*/
 * @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.enseval.ttss.util.MailNotif.java

public void emailGiroTolak(Giro gironya, String namaCustomer, String customerID) {

    String port = (Executions.getCurrent().getServerPort() == 80) ? ""
            : (":" + Executions.getCurrent().getServerPort());
    String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port
            + Executions.getCurrent().getContextPath() + "/info_giro.zul";

    String msg = "<html>" + "<head>"
            + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
            + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {"
            + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>"
            + "</head>" + "<p>Yth, </p>"
            + "<p>Berikut kami informasikan customer/outlet baru ditambahkan dalam daftar giro tolak;</p> "
            + "<br/>" + "<p><pre>" + "Customer ID      : " + customerID + "<br/>" + "Nama Customer    : "
            + namaCustomer + "<br/>" + "Nomor Giro       : " + gironya.getNomorGiro() + "<br/>"
            + "Nilai            : " + Rupiah.format(gironya.getNilai()) + "<br/>" + "Bank             : "
            + gironya.getBank() + "<br/>" + "Keterangan       : " + gironya.getKeterangan() + "" + "<pre>"
            + "</p>" + "<br/>" + "<br/>" + "<br/>"
            + "<p>Outlet akan di hold sementara oleh bagian Data Proses, selama di hold outlet tidak bisa melakukan order</p>"
            + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>"
            + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>";

    try {/* w  ww .  j ava2s .c  o  m*/
        HtmlEmail mail = new HtmlEmail();
        mail.setHostName(Util.setting("smtp_host"));
        mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port")));
        mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"),
                Util.setting("smtp_password")));
        mail.setFrom(Util.setting("email_from"));
        for (String s : Util.setting("email_to").split(",")) {
            mail.addTo(s.trim());
        }

        mail.setSubject("[INFO GIRO TOLAK] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : "
                + namaCustomer + " (" + customerID + ")");
        mail.setHtmlMsg(msg);
        mail.send();
    } catch (EmailException ex) {
        Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.enseval.ttss.util.MailNotif.java

public void emailTolakUpdate(Giro gironya) {

    String port = (Executions.getCurrent().getServerPort() == 80) ? ""
            : (":" + Executions.getCurrent().getServerPort());
    String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port
            + Executions.getCurrent().getContextPath() + "/info_giro.zul";

    String msg = "<html>" + "<head>"
            + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
            + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {"
            + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>"
            + "</head>" + "<p>Yth, </p>"
            + "<p>Berikut kami informasikan giro tolakan berikut sudah di proses kliring ulang;</p> " + "<br/>"
            + "<p><pre>" + "Customer ID      : " + gironya.getCustomer().getId() + "<br/>"
            + "Nama Customer    : " + gironya.getCustomer().getNama() + "<br/>" + "Nomor Giro       : "
            + gironya.getNomorGiro() + "<br/>" + "Nilai            : " + Rupiah.format(gironya.getNilai())
            + "<br/>" + "Bank             : " + gironya.getBank() + "<br/>" + "Tgl Kliring      : "
            + gironya.getTglKliring() + "<br/>" + "Keterangan       : " + gironya.getKeterangan() + "" + "<pre>"
            + "</p>" + "<br/>" + "<br/>" + "<br/>"
            + "<p>Jika tidak ada tolakan, account shipto customer akan segera diaktifkan oleh bagian Data Proses.</p>"
            + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>"
            + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>";

    try {/* w w  w  .ja  v a2  s .  c o m*/
        HtmlEmail mail = new HtmlEmail();
        mail.setHostName(Util.setting("smtp_host"));
        mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port")));
        mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"),
                Util.setting("smtp_password")));
        mail.setFrom(Util.setting("email_from"));
        for (String s : Util.setting("email_to").split(",")) {
            mail.addTo(s.trim());
        }

        mail.setSubject("[INFO GIRO TOLAK - Update] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : "
                + gironya.getCustomer().getNama() + " (" + gironya.getCustomer().getId() + ")");
        mail.setHtmlMsg(msg);
        mail.send();
    } catch (EmailException ex) {
        Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:it.vige.greenarea.test.mail.SendMailTest.java

@Test
public void testSendMailToGoogle() throws Exception {
    HtmlEmail email = new HtmlEmail();
    try {//from ww  w .j a v a 2s. c  om
        email.setSubject("prova");
        email.setHtmlMsg("<div>ciao</div>");
        email.addTo("luca.stancapiano@vige.it");
        email.setSmtpPort(587);
        email.setHostName("smtp.gmail.com");
        email.setFrom("greenareavige@gmail.com");
        email.setAuthentication("greenareavige@gmail.com", "vulitgreenarea");
        email.setTLS(true);
        email.send();
    } catch (EmailException e) {
        fail();
    }

}

From source file:com.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 w w  .j a va  2s . c o  m*/
        HtmlEmail email = new HtmlEmail();
        email.setHostName(emailConf.getHost());
        email.setSmtpPort(emailConf.getPort());
        email.setStartTLSEnabled(emailConf.getIsStartTls());
        email.setSSLOnConnect(emailConf.getIsSsl());
        email.setFrom(fromEmail, fromName);
        email.setCharset(EmailConstants.UTF_8);
        for (MailRecipientField aToEmail : toEmail) {
            if (isValidate(aToEmail.getEmail()) && isValidate(aToEmail.getName())) {
                email.addTo(aToEmail.getEmail(), aToEmail.getName());
            } else {
                LOG.error(String.format("Invalid to email input: %s---%s", aToEmail.getEmail(),
                        aToEmail.getName()));
            }
        }

        if (CollectionUtils.isNotEmpty(ccEmail)) {
            for (MailRecipientField aCcEmail : ccEmail) {
                if (isValidate(aCcEmail.getEmail()) && isValidate(aCcEmail.getName())) {
                    email.addCc(aCcEmail.getEmail(), aCcEmail.getName());
                } else {
                    LOG.error(String.format("Invalid cc email input: %s---%s", aCcEmail.getEmail(),
                            aCcEmail.getName()));
                }
            }
        }

        if (CollectionUtils.isNotEmpty(bccEmail)) {
            for (MailRecipientField aBccEmail : bccEmail) {
                if (isValidate(aBccEmail.getEmail()) && isValidate(aBccEmail.getName())) {
                    email.addBcc(aBccEmail.getEmail(), aBccEmail.getName());
                } else {
                    LOG.error(String.format("Invalid bcc email input: %s---%s", aBccEmail.getEmail(),
                            aBccEmail.getName()));
                }
            }
        }

        if (emailConf.getUser() != null) {
            email.setAuthentication(emailConf.getUser(), emailConf.getPassword());
        }

        email.setSubject(subject);

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

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

From source file:enviocorreo.EnviadorCorreo.java

/**
 * Enva un correo electrnico. Utiliza la biblioteca Apache Commons Email,
 * accesible va <a href="https://commons.apache.org/proper/commons-email/">https://commons.apache.org/proper/commons-email/</a>
 *
 * @param destinatario//from  w  w  w. j a v  a  2  s.  com
 * @param asunto
 * @param mensaje
 * @return
 */
public boolean enviarCorreoE(String destinatario, String asunto, String mensaje) {
    boolean resultado = false;

    HtmlEmail email = new HtmlEmail();
    email.setHostName(host);
    email.setSmtpPort(puerto);
    email.setAuthenticator(new DefaultAuthenticator(usuario, password));

    if (isGmail) {
        email.setSSLOnConnect(true);
    } else {
        email.setStartTLSEnabled(true);
    }

    try {
        email.setFrom(usuario + "<dominio del correo>");
        email.setSubject(asunto);
        email.setHtmlMsg(mensaje);
        email.addTo(destinatario);
        email.send();
        resultado = true;
    } catch (EmailException eme) {
        mensaje = "Ocurri un error al hacer el envo de correo.";
        mensajeError = eme.toString();
    }

    return resultado;
}