Package org.apache.commons.mail

Examples of org.apache.commons.mail.Email


                System.out.println(password);
                System.out.println(host);
                System.out.println(needAuth);
            }

            Email email;
            if (html) {
                email = new HtmlEmail();
            } else {
                email = new SimpleEmail();
            }
            email.setHostName(host);
            if (needAuth.equalsIgnoreCase("true")) {
                email.setAuthentication(username, password);
            }
            email.addTo(to);
            if (cc != null && cc.length() > 0) email.addCc(cc);
            if (bcc != null && bcc.length() > 0) email.addBcc(bcc);
            email.setFrom(from, "ChaiDB Server");
            email.setSubject(subject);

            if (html) {
                ((HtmlEmail) email).setHtmlMsg(content);
            } else {
                email.setMsg(content);
            }
            email.send();
        } catch (Exception exception) {
            logger.error(exception);
            if (DEBUG) {
                System.out.println(exception.getMessage());
                exception.printStackTrace();
View Full Code Here


        LOG.debug("Sending mail to " + emailAddress);
        if(!configuration.isEmailTransportEnabled()) {
            throw new TransportConfigurationException("Email transport is not enabled!");
        }

        Email email = new SimpleEmail();
        email.setHostName(configuration.getEmailTransportHostname());
        email.setSmtpPort(configuration.getEmailTransportPort());
        if (configuration.isEmailTransportUseSsl()) {
            email.setSslSmtpPort(Integer.toString(configuration.getEmailTransportPort()));
        }

        if(configuration.isEmailTransportUseAuth()) {
            email.setAuthenticator(new DefaultAuthenticator(
                    configuration.getEmailTransportUsername(),
                    configuration.getEmailTransportPassword()
            ));
        }

        email.setSSLOnConnect(configuration.isEmailTransportUseSsl());
        email.setStartTLSEnabled(configuration.isEmailTransportUseTls());
        email.setFrom(configuration.getEmailTransportFromEmail());
        email.setSubject(buildSubject(stream, checkResult, configuration, backlog));

        StringBuilder body = new StringBuilder();
        body.append(buildBody(stream, checkResult, backlog));
        email.setMsg(body.toString());
        email.addTo(emailAddress);

        email.send();
    }
View Full Code Here

            final List<Object> recipientList = (List<Object>) infoMap.get(RECIPIENTS);
            // From
            final Object from = infoMap.get(FROM);
            final Object replyTo = infoMap.get(REPLY_TO);

            Email email = null;
            if (infoMap.get(ATTACHMENTS) == null) {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new SimpleEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }

            } else {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new MultiPartEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(from.toString());
                    email.setFrom(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.setFrom(from.toString());
                }

            }

            if (replyTo != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(replyTo.toString());
                    email.addReplyTo(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.addReplyTo(replyTo.toString());
                }

            }

            if (recipientList != null) {
                for (Object recipient : recipientList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(recipient.toString());
                        email.addTo(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addTo(recipient.toString());
                    }
                }
            } else {
                throw new MailException("You must specify at least one recipient.");
            }


            List<Object> ccsList = (List<Object>) infoMap.get(CCS);
            if (ccsList != null) {
                for (Object cc : ccsList) {
                    email.addCc(cc.toString());
                }
            }

            List<Object> bccsList = (List<Object>) infoMap.get(BCCS);
            if (bccsList != null) {

                for (Object bcc : bccsList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(bcc.toString());
                        email.addBcc(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addBcc(bcc.toString());
                    }
                }
            }
            if (!StringUtils.isEmpty(charset)) {
                email.setCharset(charset);
            }

            email.setSubject(subject);
            email.updateContentType(TEXT_HTML);

            if (headers != null) {
                for (String key : headers.keySet()) {
                    email.addHeader(key, headers.get(key));
                }
            }
            // reset the infomap
            infos.remove();
            return Mail.send(email);
View Full Code Here

            final List<Object> recipientList = (List<Object>) infoMap.get(RECIPIENTS);
            // From
            final Object from = infoMap.get(FROM);
            final Object replyTo = infoMap.get(REPLY_TO);

            Email email = null;
            if (infoMap.get(ATTACHMENTS) == null) {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new SimpleEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }

            } else {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new MultiPartEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(from.toString());
                    email.setFrom(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.setFrom(from.toString());
                }

            }

            if (replyTo != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(replyTo.toString());
                    email.addReplyTo(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.addReplyTo(replyTo.toString());
                }

            }

            if (recipientList != null) {
                for (Object recipient : recipientList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(recipient.toString());
                        email.addTo(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addTo(recipient.toString());
                    }
                }
            } else {
                throw new MailException("You must specify at least one recipient.");
            }


            List<Object> ccsList = (List<Object>) infoMap.get(CCS);
            if (ccsList != null) {
                for (Object cc : ccsList) {
                    email.addCc(cc.toString());
                }
            }

            List<Object> bccsList = (List<Object>) infoMap.get(BCCS);
            if (bccsList != null) {

                for (Object bcc : bccsList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(bcc.toString());
                        email.addBcc(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addBcc(bcc.toString());
                    }
                }
            }
            if (!StringUtils.isEmpty(charset)) {
                email.setCharset(charset);
            }

            email.setSubject(subject);
            email.updateContentType(TEXT_HTML);

            if (headers != null) {
                for (String key : headers.keySet()) {
                    email.addHeader(key, headers.get(key));
                }
            }
            // reset the infomap
            infos.remove();
            return Mail.send(email);
View Full Code Here

        }

        if (StringUtils.isBlank(templatePath)) {
            throw new IllegalArgumentException("Template path is null or empty");
        }
        Email email = getEmail(templatePath, emailParams);

        if (email == null) {
            throw new IllegalArgumentException("Error while creating template");
        }

        MessageGateway<Email> messageGateway = messageGatewayService.getGateway(email.getClass());

        for (InternetAddress address : recipients) {
            try {
                email.setTo(Collections.singleton(address));
                messageGateway.send(email);
            } catch (Exception e) {
                failureList.add(address);
                log.error("Exception sending email to " + address, e);
            }
View Full Code Here

               return null;
           }

           Class<? extends Email> emailClass = templatePath.endsWith(".html") ? HtmlEmail.class : SimpleEmail.class;

           final Email email = mailTemplate.getEmail(StrLookup.mapLookup(emailParams), emailClass);

           if (emailParams.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)
                    && emailParams.containsKey(EmailServiceConstants.SENDER_NAME)) {
                email.setFrom(emailParams.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS),
                        emailParams.get(EmailServiceConstants.SENDER_NAME));
           } else if (emailParams.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)) {
                email.setFrom(emailParams.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS));
           }

           return email;

        } catch (Exception e) {
View Full Code Here

    String subjectStr = getStringFromField(subject, execution);
    String textStr = getStringFromField(text, execution);
    String htmlStr = getStringFromField(html, execution);
    String charSetStr = getStringFromField(charset, execution);

    Email email = createEmail(textStr, htmlStr);

    addTo(email, toStr);
    setFrom(email, fromStr);
    addCc(email, ccStr);
    addBcc(email, bccStr);
    setSubject(email, subjectStr);
    setMailServerProperties(email);
    setCharset(email, charSetStr);

    try {
      email.send();
    } catch (EmailException e) {
      throw new ProcessEngineException("Could not send e-mail", e);
    }
    leave(execution);
  }
View Full Code Here

   * @param to
   * @param message
   * @throws Exception
   */
  private static void sendEmail(String mailserver, int port, String from, String to, String message, String username, String password) throws EmailException
    Email email = new SimpleEmail();
    email.setDebug(false); // true if you want to debug
        email.setHostName(mailserver);
        if (username != null) {
      email.setAuthentication(username, password);
          email.getMailSession().getProperties().put(
             "mail.smtp.starttls.enable", "true");
    }
        email.setFrom(from, "Wookie Server");
        email.setSubject("Wookie API Key");
        email.setMsg(message);
        email.addTo(to);
        email.send();
  }
View Full Code Here

            }
        }

        Map<String,Object> context = newHashMap(options.getContext());
        context.put("toFullName", toName);
        Email email = new SimpleEmail();
        try
        {
            email.setHostName("localhost");
            email.setSmtpPort(2525);
            email.setFrom(options.getFromEmail(), options.getFromName());
            email.setSubject("[test] " + render(options.getSubjectTemplate(), context));
            email.setMsg(render(options.getBodyTemplate(), context));
            email.addTo(toEmail);
            if (options.getReplyToEmail() != null)
            {
                email.setReplyTo(Arrays.asList(new InternetAddress(options.getReplyToEmail())));
            }

            email.send();
        }
        catch (EmailException e)
        {
            log.error("Unable to send email", e);
            if (log.isDebugEnabled())
            {
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                try
                {
                    email.getMimeMessage().writeTo(bout);
                    log.debug("Sent email:\n" + new String(bout.toByteArray()));
                }
                catch (MessagingException ex)
                {
                    throw new RuntimeException(ex);
View Full Code Here

            final List<Object> recipientList = (List<Object>) infoMap.get(RECIPIENTS);
            // From
            final Object from = infoMap.get(FROM);
            final Object replyTo = infoMap.get(REPLY_TO);

            Email email = null;
            if (infoMap.get(ATTACHMENTS) == null) {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new SimpleEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }

            } else {
//                if (StringUtils.isEmpty(bodyHtml)) {
//                    email = new MultiPartEmail();
//                    email.setMsg(bodyText);
//                } else {
                    HtmlEmail htmlEmail = new HtmlEmail();
                    htmlEmail.setHtmlMsg(bodyHtml);
//                    if (!StringUtils.isEmpty(bodyText)) {
//                        htmlEmail.setTextMsg(bodyText);
//                    }
                    email = htmlEmail;
//                }
                MultiPartEmail multiPartEmail = (MultiPartEmail) email;
                List<EmailAttachment> objectList = (List<EmailAttachment>) infoMap.get(ATTACHMENTS);
                for (EmailAttachment object : objectList) {
                    multiPartEmail.attach(object);
                }
            }

            if (from != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(from.toString());
                    email.setFrom(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.setFrom(from.toString());
                }

            }

            if (replyTo != null) {
                try {
                    InternetAddress iAddress = new InternetAddress(replyTo.toString());
                    email.addReplyTo(iAddress.getAddress(), iAddress.getPersonal());
                } catch (Exception e) {
                    email.addReplyTo(replyTo.toString());
                }

            }

            if (recipientList != null) {
                for (Object recipient : recipientList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(recipient.toString());
                        email.addTo(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addTo(recipient.toString());
                    }
                }
            } else {
                throw new MailException("You must specify at least one recipient.");
            }


            List<Object> ccsList = (List<Object>) infoMap.get(CCS);
            if (ccsList != null) {
                for (Object cc : ccsList) {
                    email.addCc(cc.toString());
                }
            }

            List<Object> bccsList = (List<Object>) infoMap.get(BCCS);
            if (bccsList != null) {

                for (Object bcc : bccsList) {
                    try {
                        InternetAddress iAddress = new InternetAddress(bcc.toString());
                        email.addBcc(iAddress.getAddress(), iAddress.getPersonal());
                    } catch (Exception e) {
                        email.addBcc(bcc.toString());
                    }
                }
            }
            if (!StringUtils.isEmpty(charset)) {
                email.setCharset(charset);
            }

            email.setSubject(subject);
            email.updateContentType(TEXT_HTML);

            if (headers != null) {
                for (String key : headers.keySet()) {
                    email.addHeader(key, headers.get(key));
                }
            }
            // reset the infomap
            infos.remove();
            return Mail.send(email);
View Full Code Here

TOP

Related Classes of org.apache.commons.mail.Email

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.