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

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

Introduction

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

Prototype

public Email addTo(final String email, final String name, final String charset) throws EmailException 

Source Link

Document

Add a recipient TO to the email using the specified address, personal name, and charset encoding for the name.

Usage

From source file:br.com.hslife.orcamento.component.EmailComponent.java

public void enviarEmail() throws ApplicationException, EmailException, SendGridException {
    // Carrega as configuraes de envio de e-mail
    this.populateParameters();

    if (metodoEnvio.equals("SENDGRID")) {
        this.enviarEmailSendGrid();
        return;//from  w  w  w. ja  va 2s  . co  m
    }

    // Instancia o objeto de e-mail
    SimpleEmail email = new SimpleEmail();

    // Atribui ao objeto os parmetros passados ao mtodo
    email.addTo(emailDestinatario, destinatario, charset);
    email.setFrom(emailRemetente, remetente, charset); // remetente
    email.setSubject(assunto);
    email.setMsg(mensagem);

    // Atribui os demais parmetros vindos de opes do sistema
    email.setHostName(servidor);
    email.setSmtpPort(porta);
    email.setAuthentication(usuario, senha);
    if (usarSSL) {
        email.setSSLOnConnect(true);
        email.setSslSmtpPort(String.valueOf(porta));
    } else {
        email.setSSLOnConnect(false);
    }
    email.setCharset(charset);
    email.setSSLCheckServerIdentity(false);
    email.send();
}

From source file:br.com.cgcop.administrativo.modelo.ContaEmail.java

public void enviarEmail(List<String> destinos, String mensagem, String titulo) throws EmailException {
    SimpleEmail email = new SimpleEmail();

    email.setHostName(this.host);
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(this.porta);

    //Adicione os destinatrios
    for (String destino : destinos) {
        email.addTo(destino, "", "UTF-8");
    }/*from ww  w. ja v  a  2 s  .  c om*/
    email.setSentDate(new Date());

    //Configure o seu Email do qual enviar
    email.setFrom(this.email, this.empresa.getNome());
    //Adicione um assunto
    email.setSubject(titulo);
    //Adicione a mensagem do Email
    email.setMsg(Jsoup.parse(mensagem).text());
    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    email.setTLS(true);
    email.setSSL(true);

    email.setAuthentication(this.email, this.senha);
    email.send();
}