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:ch.sbb.releasetrain.utils.emails.SMTPUtilImpl.java

@Override
public void send(String absender, String empfaenger, String betreff, String text) {
    try {// ww w. j a v a2s .c  o m
        final Email email = new SimpleEmail();
        email.setHostName(mailhost);
        email.setSmtpPort(mailport);
        email.setFrom(absender);
        email.setSubject(betreff);
        email.setMsg(text);
        email.addTo(empfaenger);
        email.send();
        log.info("mail sent to: " + empfaenger);
    } catch (final EmailException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:com.packtpub.e4.advanced.event.mailman.MailSender.java

@Override
public void handleEvent(Event event) {
    String topic = event.getTopic();
    if (topic.startsWith("smtp/")) {
        String importance = topic.substring("smtp/".length());
        String to = (String) event.getProperty("To");
        String from = (String) event.getProperty("From");
        String subject = (String) event.getProperty("Subject");
        String body = (String) event.getProperty("DATA");
        try {//w w  w .ja v  a  2s.co m
            Email email = new SimpleEmail();
            email.setDebug(false);
            email.setHostName(hostname);
            email.setSmtpPort(port);
            email.setFrom(from);
            email.addTo(to);
            email.setSubject(subject);
            email.setMsg(body);
            email.addHeader("Importance", importance);
            email.send();
            log(LogService.LOG_INFO, "Message sent successfully to " + to);
        } catch (EmailException e) {
            log(LogService.LOG_ERROR, "Error occurred" + e);
        }
    }
}

From source file:com.clavain.alerts.Methods.java

private static void sendMail(String title, String message, String emailaddy) {
    try {//  w ww.j  av  a2  s  .  c  o  m
        Email email = new SimpleEmail();
        email.setHostName(p.getProperty("mailserver.host"));
        email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port")));
        if (p.getProperty("mailserver.useauth").equals("true")) {
            email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass"));
        }
        if (p.getProperty("mailserver.usessl").equals("true")) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(p.getProperty("mailserver.from"));
        email.setSubject("[MuninMX] " + title);
        email.setMsg(message);
        email.addTo(emailaddy);
        email.send();
    } catch (Exception ex) {
        logger.warn("Unable to send Mail: " + ex.getLocalizedMessage());
    }
}

From source file:com.moss.error_reporting.server.Notifier.java

private void prepEmail(Email email, ReportId id) throws EmailException {
    email.setHostName(smtpServer);//from w ww. j a  v a2 s . c o  m
    for (String recipient : emailRecipients) {
        email.addTo(recipient);
    }

    //      email.addTo(emailRecipients.get(0));
    email.setFrom(emailFromAddress, "Error Report Server");
    email.setSubject("Error Report Received: " + id.getUuid());
}

From source file:iddb.core.util.MailManager.java

public void sendMail(String subject, String template, String[] dest, Map<String, String> args)
        throws Exception {
    if (props == null)
        throw new Exception("Unable to access email subsystem.");
    try {//from  w w w .  j  a  va2  s.co m
        Email email = new SimpleEmail();
        email.setSubject(subject);
        email.setMsg(TemplateManager.getTemplate(template, args));
        for (String adr : dest) {
            email.addTo(adr);
        }
        email.setCharset("ISO-8859-1");
        setEmailProps(email);
        email.send();
    } catch (Exception e) {
        log.error("{}: {}", e.getClass().getName(), e.getMessage());
        throw new Exception("We are unable to send your message right now.");
    }
}

From source file:com.patrolpro.beans.ContactUsBean.java

public String sendEmail() {
    try {// ww  w .  jav a  2  s.  co m
        StringBuilder emailMessage = new StringBuilder();
        emailMessage.append("From: " + this.name + "\r\n");
        emailMessage.append("Email: " + this.email + "\r\n");
        emailMessage.append("Phone: " + this.phone + "\r\n");
        emailMessage.append(message);

        Email htmlEmail = new SimpleEmail();
        htmlEmail.setMsg(message);
        htmlEmail.setFrom("contact@patrolpro.com");
        htmlEmail.setSubject("Contact Us Email");
        htmlEmail.addTo("rharris@ainteractivesolution.com");
        htmlEmail.addCc("ijuneau@ainteractivesolution.com");
        htmlEmail.addCc("jc@champ.net");
        htmlEmail.setMsg(emailMessage.toString());

        htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3"));
        htmlEmail.setHostName("mail2.champ.net");
        htmlEmail.setSmtpPort(587);
        htmlEmail.send();
        return "sentContactEmail";
    } catch (Exception exe) {

    }
    return "invalid";
}

From source file:com.turn.sorcerer.util.email.Emailer.java

private void sendEmail() throws EmailException, UnknownHostException {

    List<String> addresses = Lists
            .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins()));
    logger.info("Sending email to {}", addresses.toString());

    Email email = new HtmlEmail();
    email.setHostName(ADMIN_EMAIL.getHost());
    email.setSocketTimeout(30000); // 30 seconds
    email.setSocketConnectionTimeout(30000); // 30 seconds
    for (String address : addresses) {
        email.addTo(address);
    }//from   w w  w  .j  av a2 s.  com
    email.setFrom(
            SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName());
    email.setSubject(title);
    email.setMsg(body);
    email.send();

}

From source file:br.com.recursive.biblioteca.servicos.EmailService.java

public void sendHtmlEmail(Pessoa pessoa) throws EmailException {

    Email email = new HtmlEmail();
    email.setAuthenticator(new DefaultAuthenticator("claupwd@gmail.com", "@claupwd2014"));
    email.setHostName("smtp.gmail.com");
    email.setFrom("claupwd@gmail.com");
    email.setSubject("SIB Online - Recuperao de Senha");
    email.setMsg(createMessage(pessoa));
    email.addTo(pessoa.getContato().getEmail());
    email.setSSL(true);//  ww  w .  j  ava2 s  .  c om
    //Se true, exibe na saida todo o processo do envio do email
    email.setDebug(true);
    email.send();
}

From source file:net.sasasin.sreader.batch.publish.GMailPublisher.java

@Override
public void publish(ContentViewId content) {
    try {//from   w  w  w.  ja va  2 s.  c  om
        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setStartTLSEnabled(true);
        email.setCharset("UTF-8");

        email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword()));

        email.setFrom(content.getEmail());
        email.addTo(content.getEmail());
        email.setSubject(content.getTitle());
        email.setMsg(content.getUrl() + "\n" + content.getFullText());

        email.send();
        log(content);
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:iddb.core.util.MailManager.java

public void sendAdminMail(String subject, String message, String replyTo) throws Exception {
    if (props == null)
        throw new Exception("Unable to access email subsystem.");
    try {// w  w w .  ja v a 2s  . co m
        Email email = new SimpleEmail();
        email.setSubject(subject);
        email.setMsg(message);
        if (replyTo != null) {
            email.addReplyTo(replyTo);
        }
        for (String adr : props.getProperty("admin").split(";")) {
            email.addTo(adr);
        }
        setEmailProps(email);
        email.send();
    } catch (Exception e) {
        log.error("{}: {}", e.getClass().getName(), e.getMessage());
        throw new Exception("We are unable to send your message right now.");
    }
}