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.unibas.fittingwizard.application.tools.Notifications.java

private void sendMailTesting() {
    try {//from  w  w  w.  j  a  v a 2s.  c  o m
        Email email = new SimpleEmail();
        email.setMailSession(Session.getDefaultInstance(props));

        email.setSubject("Test mail");
        email.setMsg("This is a test mail for checking parameters from config file");
        email.setFrom(getSender().trim());
        email.addTo(getRecipient().trim());

        email.send();
    } catch (EmailException e) {
        throw new RuntimeException("Could not send notification.", e);
    }
}

From source file:ch.unibas.fittingwizard.application.tools.Notifications.java

private void sendErrorLogByMail() {
    try {/*w  ww  .  j av a  2s .  co m*/
        Email email = new SimpleEmail();
        email.setMailSession(Session.getDefaultInstance(props));

        email.setSubject("Log of FW session");
        email.setMsg(new String(Files.readAllBytes(Paths.get("fw-log.txt"))));
        email.setFrom(getSender().trim());
        email.addTo(getRecipient().trim());

        email.send();
    } catch (IOException | EmailException e) {
        throw new RuntimeException("Could not send notification.", e);
    }
}

From source file:br.com.jvmsoftware.util.EnviarMail.java

public void emailSimples(PubConfigEmpresa conf, PubUsuario usu, String msg, String subj) throws EmailException {

    Email email = new SimpleEmail();
    email.setHostName(conf.getMailEnvioSmtp());
    email.setSmtpPort(conf.getMailEnvioPorta());
    email.setAuthenticator(new DefaultAuthenticator(conf.getMailEnvio(), conf.getMailEnvioSenha()));
    email.setSSLOnConnect(true);//  w  w  w  .ja  va2  s. c o  m
    email.setFrom(conf.getMailEnvio());
    email.setSubject(subj);
    email.setMsg(msg);
    email.addTo(usu.getEmail());
    email.send();
}

From source file:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java

protected void addTo(Email email, String to) {
    String[] tos = splitAndTrim(to);
    if (tos != null) {
        for (String t : tos) {
            try {
                email.addTo(t);
            } catch (EmailException e) {
                throw new ActivitiException("Could not add " + t + " as recipient", e);
            }/*from   w  w  w .  ja  v  a 2 s. c  om*/
        }
    } else {
        throw new ActivitiException("No recipient could be found for sending email");
    }
}

From source file:com.kylinolap.common.util.MailService.java

/**
 * /*from w w  w.  j  a va 2 s.  c  om*/
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content) throws IOException {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}

From source file:ch.unibas.fittingwizard.application.tools.Notifications.java

private void sendMailGaussian(boolean isLogValid) {
    try {//from   w ww . j  a va  2s.c  o  m
        Email email = new SimpleEmail();
        email.setMailSession(Session.getDefaultInstance(props));

        email.setSubject("Gaussian calculation finished");
        email.setMsg("Gaussian calculation finished. Log file validation returned: " + isLogValid);
        email.setFrom(getSender().trim());
        email.addTo(getRecipient().trim());

        email.send();
    } catch (EmailException e) {
        throw new RuntimeException("Could not send notification.", e);
    }
}

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

private void addToAddresses(Email email, Collection<String> to) throws EmailException {
    for (String address : to) {
        if (StringUtils.isNotBlank(address)) {
            email.addTo(address);
        } else {/*from   w  ww.  ja  v a 2 s. c  om*/
            throw new IllegalArgumentException("blank TO address");
        }
    }
}

From source file:com.intuit.wasabi.email.impl.EmailServiceImpl.java

void send(String subject, String msg, String... to) {

    String[] clearTo = removeInvalidEmails(to);

    if (isActive()) {
        try {//from   w w w.  j  av a2  s  . c  o  m
            Email email = createSimpleMailService();
            email.setHostName(host);
            email.setFrom(from);
            email.setSubject(subjectPrefix + " " + subject);
            email.setMsg(msg);
            email.addTo(clearTo);
            email.send();
        } catch (EmailException mailExcp) {
            LOGGER.error("Email could not be send because of " + mailExcp.getMessage());
            throw new WasabiEmailException("Email: " + emailToString(subject, msg, to) + " could not be sent.",
                    mailExcp);
        }
    } else {
        //if the service is not active log the email that would have been send and throw error
        LOGGER.info("EmailService would have sent: " + emailToString(subject, msg, to));
        throw new WasabiEmailException(ErrorCode.EMAIL_NOT_ACTIVE_ERROR, "The EmailService is not active.");
    }
}

From source file:com.cqecom.cms.components.eMailer.TrialOsubEmailController.java

public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
    try {/*from  ww  w  . j av  a 2 s.c om*/
        String strLicenseName = "";
        String strLicensePassword = "";
        String strLanguageName = "";
        String strEndsAt = "";
        String strLanguageSlug = "";
        String strTrialUrl = "";
        String strOfferPromo = "";
        String strEmailTemplateUrl = "";
        String strFollowupEmailTemplateUrl = "";
        String strEmailSubject = "";
        String strEmailFrom = "";
        String followupEmail = "";
        String strFollowupEmailSubject = "";

        if (request != null) {
            strLicenseName = getParamValue(request, "license_name");
            strLicensePassword = getParamValue(request, "license_password");
            strLanguageName = getParamValue(request, "language_name");
            strEndsAt = getParamValue(request, "ends_at");
            strLanguageSlug = getParamValue(request, "language_slug");
            strTrialUrl = getParamValue(request, "trial_url");
            strOfferPromo = getParamValue(request, "offer_promo");
            strEmailTemplateUrl = getParamValue(request, "email_template_url");
            strFollowupEmailTemplateUrl = getParamValue(request, "followup_email_template_url");
            strEmailSubject = getParamValue(request, "email_subject");
            strFollowupEmailSubject = getParamValue(request, "followup_email_subject");
            strEmailFrom = getParamValue(request, "email_from");
            followupEmail = getParamValue(request, "followup_email");
        }

        if (followupEmail.equals("true")) {
            strEmailTemplateUrl = strFollowupEmailTemplateUrl;
            strEmailSubject = strFollowupEmailSubject;
        }

        session = repository.loginAdministrative(null);
        String pageHtml = session.getRootNode().getNode(strEmailTemplateUrl + "/jcr:content/content")
                .getProperty("text").getValue().getString();

        pageHtml = replaceToken(pageHtml, "license_name", strLicenseName);
        pageHtml = replaceToken(pageHtml, "license_password", strLicensePassword);
        pageHtml = replaceToken(pageHtml, "language_name", strLanguageName);
        pageHtml = replaceToken(pageHtml, "ends_at", strEndsAt);
        pageHtml = replaceToken(pageHtml, "language_slug", strLanguageSlug);
        pageHtml = replaceToken(pageHtml, "trial_url", strTrialUrl);
        pageHtml = replaceToken(pageHtml, "offer_promo", strOfferPromo);
        Email emailObj = new HtmlEmail();
        emailObj.setContent(pageHtml.toString(), "text/html");

        if (!strEmailFrom.equals(""))
            emailObj.setFrom(strEmailFrom, "CqEcom " + strLanguageName + " Trial");

        if (!strLicenseName.equals(""))
            emailObj.addTo(strLicenseName);

        if (!strEmailSubject.equals(""))
            emailObj.setSubject(strEmailSubject);
        ms.sendEmail(emailObj);
        logger.info("Mail sent to => " + strLicenseName);
    } catch (Exception ex) {
        logger.info(ex.getMessage());
    } finally {
        if (session != null)
            session.logout();
    }
}

From source file:com.cognifide.qa.bb.email.EmailSender.java

public void sendEmail(final EmailData emailData) {
    try {/*from  w w w .ja v  a2 s .c  om*/
        Email email = new SimpleEmail();
        email.setHostName(smtpServer);
        email.setSmtpPort(smtpPort);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setSSLOnConnect(secure);
        email.setFrom(emailData.getAddressFrom());
        email.setSubject(emailData.getSubject());
        email.setMsg(emailData.getMessageContent());
        email.addTo(emailData.getAddressTo());
        email.send();
    } catch (org.apache.commons.mail.EmailException e) {
        throw new EmailException(e);
    }
}