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

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

Introduction

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

Prototype

public Email setFrom(final String email) throws EmailException 

Source Link

Document

Set the FROM field of the email to use the specified address.

Usage

From source file:shnakkydoodle.notifying.endpoints.EmailEndpoint.java

/**
 * Send the notification// ww w .  jav  a 2  s. c  o  m
 * 
 * @param recipient
 * @param subject
 * @param message
 * @throws Exception
 */
@Override
public void send(String recipient, String subject, String message) throws Exception {

    Email email = null;

    if (!this.properties.getProperties().containsKey("notification.email.server")
            || !this.properties.getProperties().containsKey("notification.email.port")
            || !this.properties.getProperties().containsKey("notification.email.username")
            || !this.properties.getProperties().containsKey("notification.email.password")
            || !this.properties.getProperties().containsKey("notification.email.fromemail")) {
        throw new Exception("Notification email settings incomplete");
    }

    // Determine if we need to send an html or simple email
    if (message.trim().startsWith("<")) {
        email = new HtmlEmail();
    } else {
        email = new SimpleEmail();
    }

    email.setHostName(this.properties.getProperties().get("notification.email.server").toString());
    email.setSmtpPort(
            Integer.parseInt(this.properties.getProperties().get("notification.email.port").toString()));
    email.setAuthentication(this.properties.getProperties().get("notification.email.username").toString(),
            this.properties.getProperties().get("notification.email.password").toString());
    email.setFrom(this.properties.getProperties().get("notification.email.fromemail").toString());
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(recipient);
    email.send();
}

From source file:sk.baka.webvm.analyzer.utils.NotificationDelivery.java

private static void configure(final Email mail, final Config config) throws EmailException {
    mail.setHostName(config.mailSmtpHost);
    config.mailSmtpEncryption.activate(mail);
    if (config.mailSmtpPort > 0) {
        if (mail.isSSL()) {
            mail.setSslSmtpPort(Integer.toString(config.mailSmtpPort));
        } else {/*from   www .  j  a va2  s .c  o  m*/
            mail.setSmtpPort(config.mailSmtpPort);
        }
    }
    if (config.mailSmtpUsername != null) {
        mail.setAuthentication(config.mailSmtpUsername, config.mailSmtpPassword);
    }
    mail.setFrom(config.mailFrom);
    if (config.mailTo == null) {
        config.mailTo = "";
    }
    // add recipients
    final StringTokenizer t = new StringTokenizer(config.mailTo, ",");
    for (; t.hasMoreTokens();) {
        mail.addTo(t.nextToken().trim());
    }
}

From source file:uap.workflow.engine.bpmn.behavior.MailActivityBehavior.java

protected void setFrom(Email email, String from) {
    String fromAddres = null;/*from  w  w  w . j a  v a2  s .  co  m*/

    if (from != null) {
        fromAddres = from;
    } else { // use default configured from address in process engine config
        fromAddres = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
    }

    try {
        email.setFrom(fromAddres);
    } catch (EmailException e) {
        throw new WorkflowException("Could not set " + from + " as from address in email", e);
    }
}