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

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

Introduction

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

Prototype

public abstract Email setMsg(String msg) throws EmailException;

Source Link

Document

Define the content of the mail.

Usage

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

private Email prepareSimpleMessage(Collection<String> to, Collection<String> cc, FirebirdMessage message)
        throws EmailException {
    Email email = new SimpleEmail();
    email.setSentDate(new Date());
    email.setSubject(message.getSubject());
    if (StringUtils.isBlank(overrideEmailAddress)) {
        addToAddresses(email, to);/*from ww w.j ava 2 s  .  co  m*/
        addCcAddresses(email, cc);
        email.setMsg(message.getBody());
    } else {
        email.addTo(overrideEmailAddress);
        email.setMsg(buildOverriddenEmailBody(to, cc, message));
    }
    return email;
}

From source file:com.esofthead.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");

    int mailServerPort;
    try {//from   w  w  w . j a  v  a 2  s.  co  m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        PrintWriter out = response.getWriter();
        out.write("Port must be an integer value");
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if (tls.equals("true")) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        return;
    }
}

From source file:edu.corgi.uco.sendEmails.java

public void sendConfirmation(String email2, String firstName, String lastName, int token, int id)
        throws EmailException {

    Email email = new SimpleEmail();

    email.setDebug(true);// ww w  . j  a  v a  2s  .  c  o  m
    email.setHostName("smtp.gmail.com");
    email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
    email.setStartTLSEnabled(true);
    email.setSmtpPort(587);
    email.setFrom("ucocorgi@gmail.com", "UCO CS Corgi");
    email.setSubject("Account Confirmation");
    email.setMsg(firstName + " " + lastName
            + " please go to the following address http://localhost:8080/Corgi/faces/accountAuth.xhtml "
            + "and enter the token:" + token + " and the ID:" + id + " to confirm and activate your account");
    System.out.print("Email Address: " + email2);
    email.addTo(email2);

    email.send();

}

From source file:com.googlecode.fascinator.messaging.EmailNotificationConsumer.java

private void sendEmails(List<String> toList, List<String> ccList, String subject, String body,
        String fromAddress, String fromName, boolean isHtml) throws EmailException {
    Email email = null;
    if (isHtml) {
        email = new HtmlEmail();
        ((HtmlEmail) email).setHtmlMsg(body);
    } else {/*from  w  ww. ja va2  s . c  om*/
        email = new SimpleEmail();
        email.setMsg(body);
    }
    email.setDebug(debug);
    email.setHostName(smtpHost);
    if (smtpUsername != null || smtpPassword != null) {
        email.setAuthentication(smtpUsername, smtpPassword);
    }
    email.setSmtpPort(smtpPort);
    email.setSslSmtpPort(smtpSslPort);
    email.setSSL(smtpSsl);
    email.setTLS(smtpTls);
    email.setSubject(subject);

    for (String to : toList) {
        email.addTo(to);
    }
    if (ccList != null) {
        for (String cc : ccList) {
            email.addCc(cc);
        }
    }
    email.setFrom(fromAddress, fromName);
    email.send();
}

From source file:com.basetechnology.s0.agentserver.mail.AgentMail.java

public int sendMessage(User user, String toEmail, String toName, String subject, String message,
        String messageTrailer1, String messageTrailer2) throws AgentServerException {
    try {//from   ww w.j a va  2s .c  om
        // Wait until we have mail access
        agentServer.mailAccessManager.wait(user, toEmail);

        int messageId = ++nextMessageId;
        log.info("Sending mail on behalf of user " + user.id + " with message Id " + messageId + " To: '<"
                + toName + ">" + toEmail + "' Subject: '" + subject + "'");

        Email email = new SimpleEmail();
        email.setDebug(debug);
        email.setHostName(mailServerHostName);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(mailServerUserName, mailServerUserPassword));
        email.setTLS(true);
        email.setFrom(mailServerFromEmail, mailServerFromName);
        // TODO: Reconsider whether we want to always mess with subject line
        email.setSubject(subject + " (#" + messageId + ")");
        email.setMsg(message + messageTrailer1 + (messageTrailer2 != null ? messageId + messageTrailer2 : ""));
        email.addTo(toEmail, toName);
        email.send();
        log.info("Message sent");

        // Return the message Id
        return messageId;
    } catch (EmailException e) {
        e.printStackTrace();
        throw new AgentServerException("EmailException sending email - " + e.getMessage());
    }
}

From source file:com.swissbit.ifttt.IFTTTConfgurationImpl.java

/** {@inheritDoc} */
@Override/*from  ww  w  . j  av  a2s  . c  o  m*/
public void trigger() {
    LOGGER.debug("IFTTT Email is getting sent...");

    final List<String> tags = this.retrieveHashtags(this.m_hashTags);

    if (tags.size() == 0) {
        return;
    }

    if (tags.size() > 0) {
        for (final String tag : tags) {
            try {
                final Email email = new SimpleEmail();
                email.setHostName(this.m_smtpHost);
                email.setSmtpPort(this.m_smtpPort);
                email.setAuthenticator(new DefaultAuthenticator(this.m_smtpUsername, this.m_smtpPassword));
                email.setSSL(true);
                email.setFrom(this.m_smtpUsername);
                email.setSubject(tag);
                email.setMsg("This is a test mail ... :-)");
                email.addTo(TRIGGER_EMAIL);
                email.send();
            } catch (final EmailException e) {
                LOGGER.error(Throwables.getStackTraceAsString(e));
            }
        }
    }
    LOGGER.debug("IFTTT Email is sent...Done");
}

From source file:edu.corgi.uco.sendEmails.java

public String send(String emailAddress, String studentFirstName, String studentLastName) throws EmailException {

    System.out.print("hit send");
    Email email = new SimpleEmail();
    System.out.print("created email file");
    email.setDebug(true);/*from  w w w  .  ja  v  a2  s. c om*/
    email.setHostName("smtp.gmail.com");
    email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
    email.setStartTLSEnabled(true);
    email.setSmtpPort(587);
    email.setFrom("ucocorgi@gmail.com", "UCO CS Secretary");
    email.setSubject("Advisement Update");
    email.setMsg(studentFirstName + " " + studentLastName
            + " your advisment has been processed and the hold on your account will be removed shortly");
    System.out.print("Email Address: " + emailAddress);
    email.addTo(emailAddress);

    System.out.print("added values");

    email.send();
    System.out.print("sent");

    return null;
}

From source file:com.music.service.EmailService.java

@Async
public void send(EmailDetails details) {
    if (details.getSubject() == null || !BooleanUtils
            .xor(ArrayUtils.toArray(details.getMessage() != null, details.getMessageTemplate() != null))) {
        throw new IllegalStateException(
                "Either subject or subjectKey / either template/message/messageKey should be specified");
    }/*from w  w w .j a  va2s .co m*/
    Validate.notBlank(details.getFrom());

    Email email = createEmail(details.isHtml());
    String subject = constructSubject(details);
    email.setSubject(subject);

    String emailMessage = constructEmailMessages(details);

    try {
        if (details.isHtml()) {
            ((HtmlEmail) email).setHtmlMsg(emailMessage);
        } else {
            email.setMsg(emailMessage);
        }

        for (String to : details.getTo()) {
            email.addTo(to);
        }
        email.setFrom(details.getFrom());

        email.send();
    } catch (EmailException ex) {
        logger.error("Exception occurred when sending email to " + details.getTo(), ex);
    }
}

From source file:json.JsonUI.java

public void enviandoEmail() {
    Properties login = new Properties();
    String properties = "json/login.properties";
    try {//from w  ww  .  j  av a  2  s  . c  o  m
        InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(properties);
        login.load(stream);
    } catch (IOException ex) {
        System.out.println("Erro: " + ex.getMessage());
    }
    String username = login.getProperty("hotmail.username");
    String password = login.getProperty("hotmail.password");

    try {
        Email email = new SimpleEmail();
        email.setHostName("smtp.live.com");
        email.setSmtpPort(587);
        email.setStartTLSRequired(true);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setFrom(username);
        email.setSubject(assuntoEmail.getText());
        email.setMsg(jTextAreaMsgEmail.getText());
        email.addTo(emailDestino.getText());
        email.setDebug(true);
        email.send();
        aviso.setText("Mensagem enviada.");
    } catch (EmailException ex) {
        System.out.println("Erro: " + ex.getMessage());
    }

}

From source file:in.flipbrain.controllers.BaseController.java

protected void sendEmail(String to, String subject, String body) throws EmailException {
    logger.debug("Sending email to " + to + "\nSubject: " + subject + "\nMessage: " + body);
    if ("true".equalsIgnoreCase(getConfigValue(Constants.EM_FAKE_SEND)))
        return;/*from  ww w  . ja  va2 s.  co  m*/

    Email email = new SimpleEmail();
    email.setHostName(getConfigValue("smtp.host"));
    email.setSmtpPort(Integer.parseUnsignedInt(getConfigValue("smtp.port")));
    email.setAuthenticator(
            new DefaultAuthenticator(getConfigValue("smtp.user"), getConfigValue("smtp.password")));
    email.setSSLOnConnect(Boolean.parseBoolean(getConfigValue("smtp.ssl")));
    email.setFrom(getConfigValue("smtp.sender"));
    email.setSubject(subject);
    email.setMsg(body);
    email.addTo(to);
    email.send();
}