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

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

Introduction

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

Prototype

@Deprecated
public void setSSL(final boolean ssl) 

Source Link

Document

Sets whether SSL/TLS encryption should be enabled for the SMTP transport upon connection (SMTPS/POPS).

Usage

From source file:com.sigaf.bean.MailReset.java

public static HtmlEmail conectaEmail() throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(HOSTNAME);/*ww  w  . ja  v a 2  s .c  o  m*/
    email.setSmtpPort(587);
    email.setSSL(true);
    email.setAuthenticator(new DefaultAuthenticator(USERNAME, PASSWORD));
    email.setTLS(true);
    email.setFrom(EMAILORIGEM);
    return email;
}

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  .co m*/

        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:com.fatecib.projetoemail.servlets.DAO.Enviaremail2.java

private void enviar(Email em, ConfiguracaoSQL conf, String destinatario) throws EmailException {
    try {/* w  ww .j  ava 2s .c  o  m*/
        HtmlEmail email = new HtmlEmail();
        email.setHostName(conf.getEMAILHOST());
        email.setSmtpPort(conf.getPORTASMTP());
        email.setAuthenticator(new DefaultAuthenticator(conf.getUsuario(), conf.getSENHA()));
        email.setSSL(true);
        email.setFrom(conf.getUsuario());
        email.setSubject(em.getTitulo());
        email.setHtmlMsg(em.getConteudo());
        // set the alternative message
        email.setTextMsg("Email enviado com sucesso");
        email.addTo(destinatario);
        email.send();
    } catch (Exception e) {
        throw e;
    }

}

From source file:br.com.ezequieljuliano.argos.util.SendMail.java

public void send() throws EmailException {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(server.getHostName());
    email.setAuthentication(server.getUser(), server.getPassWord());
    email.setSSL(server.isSSL());
    email.setSmtpPort(server.getPort());

    for (Involved involved : recipients) {
        email.addTo(involved.getEmail(), involved.getName());
    }/*  w  w w  .  j  a v a 2s.  c o m*/

    email.setFrom(sender.getEmail(), sender.getName());
    email.setSubject(subject);
    email.setHtmlMsg(message);
    email.setCharset("UTF-8");

    EmailAttachment att;
    for (Attachment annex : attachment) {
        att = new EmailAttachment();
        att.setPath(annex.getPath());
        att.setDisposition(EmailAttachment.ATTACHMENT);
        att.setDescription(annex.getDescription());
        att.setName(annex.getName());
        email.attach(att);
    }

    email.send();
}

From source file:br.com.mysqlmonitor.monitor.Monitor.java

private void enviarEmailDBA() {
    try {/*  w  w w  . ja  v  a2 s. c o m*/
        if (logs.length() != 0) {
            System.out.println("Divergencias: " + logs);
            for (Usuario usuario : usuarioDAO.findAll()) {
                System.out.println("Enviando email para: " + usuario.getNome());
                HtmlEmail email = new HtmlEmail();
                email.setHostName("smtp.googlemail.com");
                email.setSmtpPort(465);
                email.setAuthenticator(new DefaultAuthenticator("mysqlmonitorsuporte", "4rgvr6RM"));
                email.setSSL(true);
                email.setFrom("mysqlmonitorsuporte@gmail.com");
                email.setSubject("Log Mysql Monitor");
                email.setHtmlMsg(logs.toString());
                email.addTo(usuario.getEmail());
                email.send();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.maklerpoint.office.Schnittstellen.Email.MultiEmailSender.java

public void send() throws EmailException {

    if (files != null && urls != null) {
        attachments = new EmailAttachment[files.length + urls.length];

        int cnt = 0;

        for (int i = 0; i < files.length; i++) {
            attachments[cnt] = new EmailAttachment();
            attachments[cnt].setPath(files[i].getPath());
            attachments[cnt].setName(files[i].getName());
            attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT);

            cnt++;/*from w w  w .  j  a va 2s .c o m*/
        }

        for (int i = 0; i < urls.length; i++) {
            attachments[cnt] = new EmailAttachment();
            attachments[cnt].setURL(urls[i]);
            attachments[cnt].setName(urls[i].getFile());
            attachments[cnt].setDisposition(EmailAttachment.ATTACHMENT);
            cnt++;
        }

    } else if (files != null) {
        attachments = new EmailAttachment[files.length];

        for (int i = 0; i < files.length; i++) {
            attachments[i] = new EmailAttachment();
            attachments[i].setPath(files[i].getPath());
            attachments[i].setName(files[i].getName());
            attachments[i].setDisposition(EmailAttachment.ATTACHMENT);
        }
    } else if (urls != null) {
        attachments = new EmailAttachment[urls.length];

        for (int i = 0; i < urls.length; i++) {
            attachments[i] = new EmailAttachment();
            attachments[i].setURL(urls[i]);
            attachments[i].setName(urls[i].getFile());
            attachments[i].setDisposition(EmailAttachment.ATTACHMENT);
        }
    }

    HtmlEmail email = new HtmlEmail();
    email.setHostName(Config.get("mailHost", ""));
    email.setSmtpPort(Config.getConfigInt("mailPort", 25));

    email.setTLS(Config.getConfigBoolean("mailTLS", false));
    email.setSSL(Config.getConfigBoolean("mailSSL", false));

    //email.setSslSmtpPort(Config.getConfigInt("emailPort", 25));
    email.setAuthenticator(
            new DefaultAuthenticator(Config.get("mailUsername", ""), Config.get("mailPassword", "")));

    email.setFrom(Config.get("mailSendermail", "info@example.de"), Config.get("mailSender", null));

    email.setSubject(subject);
    email.setHtmlMsg(body);
    email.setTextMsg(nohtmlmsg);

    for (int i = 0; i < adress.length; i++) {
        email.addTo(adress[i]);
    }

    if (cc != null) {
        for (int i = 0; i < cc.length; i++) {
            email.addCc(cc[i]);
        }
    }

    if (attachments != null) {
        for (int i = 0; i < attachments.length; i++) {
            email.attach(attachments[i]);
        }
    }

    email.send();

}

From source file:br.com.asisprojetos.email.SendEmail.java

public void enviar(String toEmail[], String subject, String templateFile, List<String> fileNames, String mes,
        int codContrato) {

    try {//  w w w.j a  v a2s .co m

        String htmlFileTemplate = loadHtmlFile(templateFile);

        for (String to : toEmail) {

            String htmlFile = htmlFileTemplate;

            // Create the email message
            HtmlEmail email = new HtmlEmail();
            email.setHostName(config.getHostname());
            email.setSmtpPort(config.getPort());
            email.setFrom(config.getFrom(), config.getFromName()); // remetente
            email.setAuthenticator(
                    new DefaultAuthenticator(config.getAuthenticatorUser(), config.getAuthenticatorPassword()));
            email.setSSL(true);
            email.setSubject(subject); //Assunto

            email.addTo(to);//para

            logger.debug("Enviando Email para : [{}] ", to);

            int i = 1;

            for (String fileName : fileNames) {

                String cid;

                if (fileName.startsWith("diagnostico")) {
                    try {
                        cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName)));
                        htmlFile = StringUtils.replace(htmlFile, "$codGraph24$",
                                "<img src=\"cid:" + cid + "\">");
                    } catch (EmailException ex) {
                        logger.error("Arquivo de diagnostico nao encontrado.");
                    }
                } else if (fileName.startsWith("recorrencia")) {
                    try {
                        cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName)));
                        htmlFile = StringUtils.replace(htmlFile, "$codGraph25$",
                                "<img src=\"cid:" + cid + "\">");
                    } catch (EmailException ex) {
                        logger.error("Arquivo de recorrencia nao encontrado.");
                    }
                } else {
                    cid = email.embed(new File(String.format("%s/%s", config.getOutDirectory(), fileName)));
                    htmlFile = StringUtils.replace(htmlFile, "$codGraph" + i + "$",
                            "<img src=\"cid:" + cid + "\">");
                    i++;
                }

            }

            //apaga $codGraph$ no usado do template
            for (int t = i; t <= 25; t++) {
                htmlFile = StringUtils.replace(htmlFile, "$codGraph" + t + "$", " ");
            }

            htmlFile = StringUtils.replace(htmlFile, "$MES$", mes);
            htmlFile = StringUtils.replace(htmlFile, "$MAIL$", to);
            htmlFile = StringUtils.replace(htmlFile, "$CONTRATO$", Integer.toString(codContrato));

            email.setHtmlMsg(htmlFile);

            // set the alternative message
            email.setTextMsg("Your email client does not support HTML messages");

            // send the email
            email.send();

        }

        logger.debug("Email enviado com sucesso......");

    } catch (FileNotFoundException ex) {
        logger.error("Arquivo [{}/{}] nao encontrado para leitura.", config.getHtmlDirectory(), templateFile);
    } catch (Exception ex) {
        logger.error("Erro ao Enviar email : {}", ex);
    }

}

From source file:com.ipc.service.SignUpService.java

public String sendhtmlmail(int uid, String key, String email) throws IOException, EmailException {
    HtmlEmail sendemail = new HtmlEmail();
    sendemail.setCharset("euc-kr");
    sendemail.setHostName("smtp.worksmobile.com");
    sendemail.addTo(email);//from   ww w.ja  v  a  2s  . c o  m
    sendemail.setFrom("jinuk@ideaconcert.com", "");
    sendemail.setSubject("?  ?? ?.");
    sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1");
    sendemail.setSmtpPort(465);
    sendemail.setSSL(true); //?
    sendemail.setTLS(true);
    sendemail.setDebug(true);
    String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>? ?  ? .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span>   ? .</span><br><a href='http://localhost:8088/signup/permit?uid="
            + uid + "&key=" + key
            + "'><button style='width:150px; height:40px; background:none; border:2px solid #45d4fe; font-size:1.1rem; text-decoration: none;font-weight:bold; margin-top:10px;'></button></a></div></div></html>";
    System.out.println(htmlmsg);
    sendemail.setHtmlMsg(htmlmsg);
    try {
        sendemail.send();
    } catch (Exception e) {
        System.out.println("NOTOK");
        return "NOTOK";
    }
    return "OK";
}

From source file:com.ipc.service.SignUpService.java

public String sendpwmail(int uid, String key, String email) throws IOException, EmailException {
    System.out.println("Email : " + email);
    HtmlEmail sendemail = new HtmlEmail();
    sendemail.setCharset("euc-kr");
    sendemail.setHostName("smtp.worksmobile.com");
    sendemail.addTo(email);/* w ww .  j a v a2s .  c  o  m*/
    sendemail.setFrom("jinuk@ideaconcert.com", "");
    sendemail.setSubject("?  .");
    sendemail.setAuthentication("jinuk@ideaconcert.com", "tpxmapsb1");
    sendemail.setSmtpPort(465);
    sendemail.setSSL(true); //?
    sendemail.setTLS(true);
    sendemail.setDebug(true);
    String htmlmsg = "<html><div style='width:1000px; float:left; border-bottom:2px solid #45d4fe; padding-bottom:5px;box-sizing:border-box;'></div><div style='width:1000px;float:left; box-sizing:border-box; padding:15px;'><h2>?   .</h2><div style='width:100%; float:left; box-sizing:border-box; border:5px solid #f9f9f9; text-align:center; padding:40px 0 40px 0;'><span>  ?  <br> .<br>"
            + key + "</span></html>";
    System.out.println(htmlmsg);
    sendemail.setHtmlMsg(htmlmsg);
    try {
        sendemail.send();
    } catch (Exception e) {
        System.out.println("NOTOK");
        return "NOTOK";
    }
    return "OK";
}

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  w  w  .  j  a va 2  s.  c  om*/
    // 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();
}