Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


            Email email;
            if (html) {
                email = new HtmlEmail();
            } else {
                email = new SimpleEmail();
            }
            email.setHostName(host);
            if (needAuth.equalsIgnoreCase("true")) {
                email.setAuthentication(username, password);
            }
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

      throw new ProcessEngineException("Could not create HTML email", e);
    }
  }

  protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.setMsg(text);
      return email;
    } catch (EmailException e) {
      throw new ProcessEngineException("Could not create text-only email", e);
    }
  }
View Full Code Here

        String fromName = getContainer().getProperty(PROPERTY_ROOT + "from.name", "No reply");
        String fromEmailAddress = getContainer().getProperty(PROPERTY_ROOT + "from.address", "noreply@domain.com");
       
        try {

            SimpleEmail simpleEmail = new SimpleEmail();
            simpleEmail.setHostName(smtpHost);
            simpleEmail.setSmtpPort(port);
            if (authenticationName != null) {
                simpleEmail.setAuthentication(authenticationName, authenticationPassword);
            }
            for (Address address : emailObject.getTo()) {
                String name = address.getName();
                if (name == null) {
                    simpleEmail.addTo(address.getEmailAddress());
                } else {
                    simpleEmail.addTo(address.getEmailAddress(), name);
                }
            }
            Address from = emailObject.getFrom();
            if (from == null) {
                simpleEmail.setFrom(fromEmailAddress, fromName);
            } else {
                simpleEmail.setFrom(from.getEmailAddress(), from.getName());
            }
            simpleEmail.setSubject(emailObject.getSubject());
            simpleEmail.setMsg(emailObject.getMessage());
            simpleEmail.send();
        } catch (EmailException e) {
            throw new org.apache.isis.example.domainservice.email.EmailException(e.getMessage(), e);
        }
    }
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

   * @param conf ConnectionConfig 邮件服务器连接参数
   * @param mailAddress MailAddress 邮件地址
   * @param mail TextMail 文本内容
   */
  public void send( ConnectionConfig conf, MailAddress mailAddress, MailContent mail ){   
      SimpleEmail email = new SimpleEmail();     
      fillConfig( email,conf,mailAddress,mail );
     
      try{
        email.send();
      }catch( org.apache.commons.mail.EmailException ee){
        throw new MailException( ee );
      }   
  }
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

  public void sendEmail(Email email) throws EmailSendFailedException
  {
    try
    {
      org.apache.commons.mail.Email commonsEmail = email.getAttachmentFileName() != null ? new MultiPartEmail()
              : new SimpleEmail();

      commonsEmail.setDebug(debug);

      commonsEmail.setHostName(email.getMailHost());
      commonsEmail.addTo(email.getTo(), email.getToName());
View Full Code Here

    return "An error occurred and we trapped him: \n\n" + "URL: " + referer + "\n" + params + "Headers:\n" + headers + "User-id : "
        + (currentUser != null ? currentUser : "UNLOGGED") + "\nException: \n" + stackTrace;
  }

  public SimpleEmail toSimpleMail() throws EmailException {
    SimpleEmail email = new SimpleEmail();
    email.addTo(to);
    email.setSubject(subject);
    email.setMsg(getMsg());
    email.setFrom(from, fromName);
    return email;
  }
View Full Code Here

TOP

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

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.