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

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

Introduction

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

Prototype

public Email addTo(final String email) throws EmailException 

Source Link

Document

Add a recipient TO to the email.

Usage

From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java

/**
 * ??/*from  w  w  w. j  av a  2 s.com*/
 *
 * @param receivers
 * @param title
 * @param content
 * @return
 */
public static boolean sendMails(Collection<String> receivers, String title, String content) {
    if (receivers == null) {
        LOGGER.error("Mail receivers is null.");
        return false;
    }

    receivers.removeIf((from) -> (StringUtils.isEmpty(from)));

    if (receivers.isEmpty()) {
        LOGGER.error("Mail receivers is empty.");
        return false;
    }

    // ?? email
    HtmlEmail email = new HtmlEmail();

    try {
        //  SMTP ?????, 163 "smtp.163.com"
        email.setHostName(mailServerHost);

        email.setSmtpPort(mailServerPort);

        // ?
        email.setCharset("UTF-8");
        // 
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        // ??
        email.setFrom(mailSender, mailSender);
        // ???????-??????
        email.setAuthentication(mailSender, mailPasswd);
        // ???
        email.setSubject(title);
        // ???? HtmlEmail? HTML 
        email.setMsg(content);
        // ??
        email.send();

        return true;
    } catch (Throwable e) {
        LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e);
    }

    return false;
}

From source file:de.maklerpoint.office.Marketing.Tools.SendNewsletter.java

/**
 *
 * @param nl//from  ww  w .j  a  va2s  . co m
 * @param temail
 * @throws EmailException
 */

public static void sendTestNewsletter(NewsletterObj nl, String temail) throws EmailException {

    HtmlEmail email = new HtmlEmail();
    email.setHostName(Config.get("mailHost", null));

    if (Config.getConfigInt("mailPort", 25) != 25)
        email.setSmtpPort(Config.getConfigInt("mailPort", 25));

    if (Config.getConfigBoolean("mailAuth", true))
        email.setAuthentication(Config.get("mailUser", null), Config.get("mailPassword", null));

    email.setFrom(nl.getSenderMail(), nl.getSender());
    email.setSubject(nl.getSubject());
    email.setHtmlMsg(nl.getText());
    email.setTextMsg("Ihr E-Mail Client untersttzt keine HTML Nachrichten.");

    email.addTo(temail);
    email.send();
}

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

public static void enviaEmail(TUsuario usuario, String URI) throws EmailException, MalformedURLException {

    HtmlEmail email;
    email = conectaEmail();//w  w w . j  a  v a2s.c om
    email.setSubject("Restablece tu contrasea");

    //        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
    //        String cid2 = email.embed(url, "logo ??.gif");

    email.setHtmlMsg("<html>\n" + "     <head>\n" + "        <title>Restablece tu contrasea</title>\n"
            + "     </head>\n" + "     <body>\n"
            + "       <p>Hemos recibido una peticin para restablecer la contrasea de tu cuenta.</p>\n"
            + "       <p>Si hiciste esta peticin, haz clic en el siguiente enlace, si no hiciste esta peticin puedes ignorar este correo.</p>\n"
            + "       <p>\n" + "         <strong>Enlace para restablecer tu contrasea</strong><br>\n"
            + "         <a href='" + URI + "'> Restablecer contrasea </a>\n" + "       </p>\n"
            + "     </body>\n" + "\n" + "     </html>");

    email.setTextMsg("Your email client does not support HTML messages");
    email.addTo(usuario.getTEmpleado().getCorreoEmpleado());
    email.send();
}

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

public void SendInvitationEmail(Account sender, String toEmail) throws EmailException, MalformedURLException {
    //ImageHtmlEmail email = new ImageHtmlEmail();
    HtmlEmail email = new HtmlEmail();
    setUpHtmlEmail(email);/*from   w ww . j  ava  2 s . c  om*/
    email.addTo(toEmail);
    email.setSubject("Labanoro draug kvietimas");

    StringBuilder msg = new StringBuilder();
    //msg.append("<div><img src=\"" + baseUrl + "/images/lab  anorodraugai.JPG\"></div>");
    msg.append("<h4>Sveiki,</h4>");
    msg.append("<p>" + sender.getName() + " " + sender.getLastname()
            + " kvie?ia Jus tapti bendrijos Labanoro draugai nariu!</p>");
    msg.append("<p>T padaryti galite usiregistrav ");
    msg.append("<a href=" + "\"http://localhost:8080/LabanoroDraugai/registration/registration.html\">");
    msg.append("?ia</a></p>");

    email.setContent(msg.toString(), EmailConstants.TEXT_HTML);

    email.send();
}

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

public void sendApprovalRequestEmail(AccountApproval approval) throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    setUpHtmlEmail(email);// www.  j av  a2s.  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:it.vige.greenarea.test.mail.SendMailTest.java

@Test
public void testSendMailToGoogle() throws Exception {
    HtmlEmail email = new HtmlEmail();
    try {//from   ww  w  .j  av a2s  .  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.vicky.common.utils.sendemail.SendEmailImpl.java

@Override
public void send(Mail mail) throws Exception {
    try {//from www  . java  2s. com
        HtmlEmail htmlEmail = new HtmlEmail();
        htmlEmail.setHostName(mail.getHost());
        htmlEmail.setCharset(Mail.ENCODEING);
        htmlEmail.addTo(mail.getReceiverEmailAddress());
        htmlEmail.setFrom(mail.getSenderEmailAddress(), mail.getName());
        htmlEmail.setAuthentication(mail.getSenderUsername(), mail.getSenderPassword());
        htmlEmail.setSubject(mail.getSubject());
        htmlEmail.setMsg(mail.getMessage());
        for (MailAttach mailFile : mail.getMailAttachs()) {
            EmailAttachment attachment = new EmailAttachment();//  
            attachment.setPath(mailFile.getFilePath());//?    
            //attachment.setURL(new URL("http://www.baidu.com/moumou"));//?  
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setName(MimeUtility.encodeText(mailFile.getFileName()));//??  
            htmlEmail.attach(attachment);//,?
        }
        htmlEmail.send();
    } catch (Exception exception) {
        exception.printStackTrace();
        this.logger.error("toString" + exception.toString());
        this.logger.error("getMessage" + exception.getMessage());
        this.logger.error("exception", exception);
        throw new StatusMsgException(
                "??,??,?,?V!");
    }
}

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);//ww  w .j  a v a2 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();
}

From source file:br.com.atmatech.sac.controller.Email.java

public void emailAtendimento(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls,
        String emailto, String emailfrom, String solicitante, String nchamado, String razao, String data,
        String solicitacao, String realizacao, String tecnico, String imagem)
        throws EmailException, MalformedURLException {
    System.err.println(smtp + ":\n" + user + ":\n" + password + ":\n" + porta + ":\n" + ssl + ":\n" + tls
            + ":\n" + emailto + ":\n" + emailfrom + ":\n" + solicitante + ":\n" + nchamado + ":\n" + razao
            + ":\n" + data + ":\n" + solicitacao + ":\n" + realizacao + ":\n" + tecnico + ":\n" + imagem);
    HtmlEmail email = new HtmlEmail();
    // SimpleEmail email = new SimpleEmail();
    email.setHostName(smtp); // o servidor SMTP para envio do e-mail
    email.addTo(emailto); //destinatrio
    email.setFrom(emailfrom); // remetente        
    email.setSubject("Aviso de Atendimento - Suporte");
    // configura a mensagem para o formato HTML        
    email.setHtmlMsg(/*w w w. ja  v a2s . c  om*/
            "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">Prezado(a)Senhor(a).<br>"
                    + "<b>" + solicitante + "</b><p>" + "Informamos que o protocolo nmero&#013<b> " + nchamado
                    + "</b> foi finalizado por nossa Central de Suporte.<p>" + "Cliente<br>" + "" + razao
                    + "<p>" + "Data<br>" + "" + data + "<p>" + "Descrio do Problema<br>" + "" + solicitacao
                    + "<p>" + "Soluo<br>" + "" + realizacao + "<p>" + "Atendente<br>" + "" + tecnico + "<p>"
                    + "<b>Atenciosamente</b> Suporte Atmatech<p><p>" + imagem + " </html>");
    //email.setMsg("Teste");
    email.setAuthentication(user, password);
    email.setSmtpPort(porta);
    email.setSSL(ssl);
    email.setTLS(tls);
    email.send();
}

From source file:com.elexcode.emailservicelibrary.service.EmailSenderServiceImpl.java

@Override
public void sendEmail(EmailObject emailObject) throws Exception {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(host);/*w  ww.j  ava2 s. c o  m*/
    email.setSmtpPort(port);
    email.setAuthentication(username, password);
    for (String recipient : emailObject.getRecipients()) {
        email.addTo(recipient);
    }
    email.setFrom(username);
    email.setSubject(emailObject.getSubject());
    if (checkStringNotNullNotEmpty(emailObject.getHtmlMsg())) {
        email.setHtmlMsg(emailObject.getHtmlMsg());
    } else {
        if (checkStringNotNullNotEmpty(emailObject.getMessage())) {
            email.setTextMsg(emailObject.getMessage());
        }
    }
    email.setDebug(false);
    email.setTLS(true);
    email.setSSL(true);
    email.send();
}