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

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

Introduction

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

Prototype

@Override
public Email setMsg(final String msg) throws EmailException 

Source Link

Document

Set the message.

Usage

From source file:br.com.rp.services.EmailService.java

public static void enviarEmailRejeicao(String mensagem, String emaill) {
    new Thread() {
        public void run() {
            try {
                HtmlEmail email = configurarEmailPadrao();
                email.setSubject("Solicitao de proposta Vbank Rejeitada");
                email.addTo(emaill);/* www  .j av a2  s. c  o  m*/
                email.setMsg(mensagem);
                email.send();
            } catch (EmailException ex) {

            }
        }
    }.start();
}

From source file:br.com.rp.services.EmailService.java

public static void enviarEmailAprovacao(String mensagem, String emaill) {
    new Thread() {
        public void run() {
            try {
                HtmlEmail email = configurarEmailPadrao();
                email.setSubject("Solicitao de proposta Vbank aprovada");
                email.addTo(emaill);//from   w w w . j  a  v a 2  s.c o m
                email.setMsg(
                        "Altere sua senha no primeiro acesso!!! A senha padro de aesso de sua conta  a juno do seu cpf mais seu CEP com os caracteres especiais /n"
                                + mensagem);
                email.send();
            } catch (EmailException ex) {

            }
        }
    }.start();
}

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

/**
 * ??//  www .jav a  2 s.  co  m
 *
 * @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:io.marto.aem.utils.email.FreemarkerTemplatedMailer.java

private HtmlEmail constructEmail(final String[] recipients, String sender, final String subject,
        String template, Object model) throws EmailException {
    final HtmlEmail email = new HtmlEmail();

    email.setMsg(renderBody(template, model));
    if (subject != null) {
        email.setSubject(subject);//from   ww w  . jav  a  2s . c  om
    }
    if (sender != null) {
        email.setFrom(sender);
    }

    for (String recipient : recipients) {
        email.addTo(recipient);
    }

    return email;
}

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

/**
 * Builder method.//w w w .jav  a 2s  .  co 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;
}

From source file:com.vicky.common.utils.sendemail.SendEmailImpl.java

@Override
public void send(Mail mail) throws Exception {
    try {//  w w  w. ja va 2 s  .  co m
        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: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.co 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.hslife.imobiliaria.service.EmailService.java

/**
 * Envia email no formato HTML//from w  ww .j  a va2s  .c o m
 *
 * @param nomeRemetente
 * @param nomeDestinatario
 * @param emailRemetente
 * @param emailDestinatario
 * @param assunto
 * @param mensagem
 * @param anexo
 *
 * @throws EmailException
 * @throws MalformedURLException
 */
public void enviaEmailFormatoHtml(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem, String anexo)
        throws EmailException, MalformedURLException {

    HtmlEmail email = new HtmlEmail();

    // adiciona uma imagem ao corpo da mensagem e retorna seu id
    URL url = new URL(anexo); // URL do arquivo a ser anexado
    String cid = email.embed(url, "Anexos");

    // configura a mensagem para o formato HTML
    email.setHtmlMsg("<html>Anexos</html>");

    // configure uma mensagem alternativa caso o servidor no suporte HTML
    email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML");

    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatrio
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("realimoveis@hslife.com.br", "real123");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);

    // envia email
    email.send();
}

From source file:br.com.hslife.catu.service.EmailService.java

/**
 * Envia email no formato HTML/*from  w w  w  . j a v  a  2  s  .c  o m*/
 *
 * @param nomeRemetente
 * @param nomeDestinatario
 * @param emailRemetente
 * @param emailDestinatario
 * @param assunto
 * @param mensagem
 * @param anexo
 *
 * @throws EmailException
 * @throws MalformedURLException
 */
public void enviaEmailFormatoHtml(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem, String anexo)
        throws EmailException, MalformedURLException {

    HtmlEmail email = new HtmlEmail();

    // adiciona uma imagem ao corpo da mensagem e retorna seu id
    URL url = new URL(anexo); // URL do arquivo a ser anexado
    String cid = email.embed(url, "Anexos");

    // configura a mensagem para o formato HTML
    email.setHtmlMsg("<html>Anexos</html>");

    // configure uma mensagem alternativa caso o servidor no suporte HTML
    email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML");

    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatrio
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("realimoveis@hslife.com.br", "real123");
    email.setCharset("UTF8");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);

    // envia email
    email.send();
}

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

protected void okPressed() {
    try {//from   w w  w  .  jav  a  2 s.  c o  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());
    }
}