Example usage for org.apache.commons.mail Email MAIL_SMTP_FROM

List of usage examples for org.apache.commons.mail Email MAIL_SMTP_FROM

Introduction

In this page you can find the example usage for org.apache.commons.mail Email MAIL_SMTP_FROM.

Prototype

String MAIL_SMTP_FROM

To view the source code for org.apache.commons.mail Email MAIL_SMTP_FROM.

Click Source Link

Usage

From source file:com.itcs.commons.email.impl.RunnableSendHTMLEmail.java

public void run() {
    Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO,
            "executing Asynchronous task RunnableSendHTMLEmail");
    try {/*from   www  .  j ava2s . c  om*/
        HtmlEmail email = new HtmlEmail();
        email.setCharset("utf-8");
        email.setMailSession(getSession());
        for (String dir : to) {
            email.addTo(dir);
        }
        if (cc != null) {
            for (String ccEmail : cc) {
                email.addCc(ccEmail);
            }
        }
        if (cco != null) {
            for (String ccoEmail : cco) {
                email.addBcc(ccoEmail);
            }
        }
        email.setSubject(subject);
        // set the html message
        email.setHtmlMsg(body);
        email.setFrom(getSession().getProperties().getProperty(Email.MAIL_SMTP_FROM, Email.MAIL_SMTP_USER),
                getSession().getProperties().getProperty(Email.MAIL_SMTP_FROMNAME, Email.MAIL_SMTP_USER));
        // set the alternative message
        email.setTextMsg("Si ve este mensaje, significa que su cliente de correo no permite mensajes HTML.");
        // send the email
        if (attachments != null) {
            addAttachments(email, attachments);
        }
        email.send();
        Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.INFO,
                "Email sent successfully to:{0} cc:{1} bcc:{2}",
                new Object[] { Arrays.toString(to), Arrays.toString(cc), Arrays.toString(cco) });
    } catch (EmailException e) {
        Logger.getLogger(RunnableSendHTMLEmail.class.getName()).log(Level.SEVERE,
                "EmailException Error sending email... with properties:\n" + session.getProperties(), e);
    }
}

From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java

private String getMailSmtpFrom() {
    return mailSession.getProperty(Email.MAIL_SMTP_FROM);
}

From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java

private void handleMailSmtpFromAddress(String mailSmtpFrom) {
    if (StringUtils.isNotBlank(mailSmtpFrom)) {
        mailSession.getProperties().setProperty(Email.MAIL_SMTP_FROM, mailSmtpFrom);
    } else if (mailSession.getProperties().containsKey(Email.MAIL_SMTP_FROM)) {
        mailSession.getProperties().remove(Email.MAIL_SMTP_FROM);
    }//from  w w  w . ja  v a2  s. c  o m
}