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

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

Introduction

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

Prototype

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

Source Link

Document

Set the FROM field of the email to use 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;/*w  ww  . j  a  va  2 s  .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();
}