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

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

Introduction

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

Prototype

public Email addTo(final String... emails) throws EmailException 

Source Link

Document

Add a list of TO recipients to the email.

Usage

From source file:com.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");
    String ssl = request.getParameter("ssl");

    int mailServerPort = 25;
    try {//from   www  .  j  a va 2  s.co  m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        LOG.info("The smtp port value is not a number. We will use default port value is 25");
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if ("true".equals(tls)) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if ("true".equals(ssl)) {
            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.");
        LOG.warn("Can not login to SMTP", e);
    }
}

From source file:edu.br.tcc.ManagedBean.TrabalhosBean.java

public Formulario enviarEmail(Formulario trabalho) {
    System.out.println("entrou no metodo do mb enviarEmail");
    try {/*from   w ww . j a  v  a2s . c  o  m*/
        System.out.println("teste: " + trabalho.getEmail());

        Email emailSimples = new SimpleEmail();

        emailSimples.setHostName("smtp.live.com");
        emailSimples.setStartTLSEnabled(true);
        emailSimples.setSmtpPort(587);
        emailSimples.setDebug(true);
        emailSimples.setAuthenticator(new DefaultAuthenticator("Seu email outlook", "sua senha"));
        emailSimples.setFrom("Seu email outlook");
        emailSimples.setSubject(formulario.getAssunto());
        emailSimples.setMsg(formulario.getTexto() + "     " + caminho2 + trabalho.getMatricula() + ".docx");
        emailSimples.addTo(trabalho.getEmail());
        emailSimples.send();
    } catch (EmailException ex) {
        //   System.out.println(""+ex);
        Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.github.frapontillo.pulse.email.EmailNotifier.java

/**
 * Send an email, using the provided parameters, notifying if the pipeline succeeded or errored.
 *
 * @param parameters The {@link EmailNotifierConfig} to use.
 * @param isSuccess  {@code true} to report a success, {@code false} to report an error.
 *///from  ww w  .ja  va  2s . c o m
private void sendEmail(EmailNotifierConfig parameters, boolean isSuccess) {
    if (parameters.getAddresses() == null || parameters.getAddresses().length == 0) {
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(parameters.getHost());
        email.setSmtpPort(parameters.getPort());
        email.setAuthenticator(new DefaultAuthenticator(parameters.getUsername(), parameters.getPassword()));
        email.setSSLOnConnect(parameters.getUseSsl());
        email.setFrom(parameters.getFrom());
        email.setSubject(parameters.getSubject());
        String body;
        if (isSuccess) {
            body = parameters.getBodySuccess();
        } else {
            body = parameters.getBodyError();
        }
        body = body.replace("{{NAME}}", getProcessInfo().getName());
        email.setMsg(body);
        email.addTo(parameters.getAddresses());
        email.send();
    } catch (EmailException e) {
        logger.error(e);
        e.printStackTrace();
    }
}

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  ww. ja v a 2 s . 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 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:net.scran24.user.server.services.HelpServiceImpl.java

private void sendEmailNotification(String name, String surveyId, String number, List<String> addresses) {
    Email email = new SimpleEmail();

    email.setHostName(smtpHostName);//w w  w.j  a  va 2s .co m
    email.setSmtpPort(smtpPort);
    email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
    email.setSSLOnConnect(true);
    email.setCharset(EmailConstants.UTF_8);

    try {
        email.setFrom(fromEmail, fromName);
        email.setSubject("Someone needs help completing their survey");
        email.setMsg("Please call " + name + " on " + number + " (survey id: " + surveyId + ")");

        for (String address : addresses)
            email.addTo(address);

        email.send();
    } catch (EmailException e) {
        log.error("Failed to send e-mail notification", e);
    }
}

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);/*from  www .j  av  a2 s .com*/
    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:adams.core.net.SimpleApacheSendEmail.java

/**
 * Sends an email.//from   www.  ja  v a  2  s.  c  o  m
 *
 * @param email   the email to send
 * @return      true if successfully sent
 * @throws Exception   in case of invalid internet addresses or messaging problem
 */
@Override
public boolean sendMail(Email email) throws Exception {
    org.apache.commons.mail.Email mail;
    String id;
    MultiPartEmail mpemail;
    EmailAttachment attachment;

    if (email.getAttachments().length > 0) {
        mail = new MultiPartEmail();
        mpemail = (MultiPartEmail) mail;
        for (File file : email.getAttachments()) {
            attachment = new EmailAttachment();
            attachment.setPath(file.getAbsolutePath());
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setName(file.getName());
            mpemail.attach(attachment);
        }
    } else {
        mail = new SimpleEmail();
    }
    mail.setFrom(email.getFrom().getValue());
    for (EmailAddress address : email.getTo())
        mail.addTo(address.getValue());
    for (EmailAddress address : email.getCC())
        mail.addCc(address.getValue());
    for (EmailAddress address : email.getBCC())
        mail.addBcc(address.getValue());
    mail.setSubject(email.getSubject());
    mail.setMsg(email.getBody());
    mail.setHostName(m_Server);
    mail.setSmtpPort(m_Port);
    mail.setStartTLSEnabled(m_UseTLS);
    mail.setSSLOnConnect(m_UseSSL);
    if (m_RequiresAuth)
        mail.setAuthentication(m_User, m_Password.getValue());
    mail.setSocketTimeout(m_Timeout);
    try {
        id = mail.send();
        if (isLoggingEnabled())
            getLogger().info("Message sent: " + id);
    } catch (Exception e) {
        getLogger().log(Level.SEVERE, "Failed to send email: " + mail, e);
        return false;
    }

    return true;
}

From source file:FacultyAdvisement.ImagineBean.java

public String submitRequest() {

    String emailCourses = "";

    for (Course c : currentCourses) {
        emailCourses += "<li>" + c.getSubject() + " " + c.getNumber() + "</li>";
    }//w w w.  j ava2s  .  c o m

    try {
        Email email = new HtmlEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234"));
        email.setSSLOnConnect(true);
        email.setFrom("uco.faculty.advisement@gmail.com");
        email.setSubject("Microsoft Imagine Account");
        email.setMsg("<font size=\"3\" style=\"font-family:verdana\"> \n" + "<ul><li>Student Name: "
                + student.getFirstName() + " " + student.getLastName() + "</li><li>Student Major: "
                + student.getMajorCode() + "<li>Current Courses: <ol>" + emailCourses + "</ol></li></ul> "
                + "Student Email if needed for response: " + student.getUsername()
                + "\n<p align=\"center\">UCO Faculty Advisement</p></font>");
        email.addTo("uco.faculty.advisement@gmail.com");
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex);
    }

    return "/customerFolder/imagineConfirm";
}

From source file:com.irurueta.server.commons.email.ApacheMailSender.java

/**
 * Internal method to send email using Apache Mail.
 * @param m email message./*ww  w.j  a v a 2 s. com*/
 * @param email apache email message.
 * @throws NotSupportedException if feature is not supported.
 * @throws EmailException if Apache Mail cannot send email.
 * @throws com.irurueta.server.commons.email.EmailException if sending
 * email fails.
 */
private void internalSendApacheEmail(EmailMessage m, Email email)
        throws NotSupportedException, EmailException, com.irurueta.server.commons.email.EmailException {
    email.setHostName(mMailHost);
    email.setSmtpPort(mMailPort);
    if (mMailId != null && !mMailId.isEmpty() && mMailPassword != null && !mMailPassword.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(mMailId, mMailPassword));
    }
    email.setStartTLSEnabled(true);
    email.setFrom(mMailFromAddress);
    if (m.getSubject() != null) {
        email.setSubject(m.getSubject());
    }
    m.buildContent(email);

    //add destinatoins
    for (String s : (List<String>) m.getTo()) {
        email.addTo(s);
    }

    for (String s : (List<String>) m.getCC()) {
        email.addCc(s);
    }

    for (String s : (List<String>) m.getBCC()) {
        email.addBcc(s);
    }

    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  w  w  .j a v  a2 s.  c o m*/
        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();
}