Package com.blazebit.mail

Examples of com.blazebit.mail.MailException


  public SimpleMailSender(String host, Integer port, String username,
      String password, MailTransport transport) {

    if (host == null || host.trim().equals("")) {
      throw new MailException(MailException.MISSING_HOST);
    } else if ((password != null && !password.trim().equals(""))
        && (username == null || username.trim().equals(""))) {
      throw new MailException(MailException.MISSING_USERNAME);
    }

    this.transport = transport;
    this.session = createMailSession(host, port, username, password);
  }
View Full Code Here


        t.connect();
        t.sendMessage(message, message.getAllRecipients());
        t.close();
      } catch (UnsupportedEncodingException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        throw new MailException(String.format(
            MailException.INVALID_ENCODING, e.getMessage()));
      } catch (MessagingException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        throw new MailException(String.format(
            MailException.GENERIC_ERROR, e.getMessage()), e);
      } finally {
        transport.clearTemporaryTrustedHosts();
      }
    }
View Full Code Here

  public SimpleMailSender(String host, Integer port, String username,
      String password, MailTransport transport) {

    if (host == null || host.trim().equals("")) {
      throw new MailException(MailException.MISSING_HOST);
    } else if ((password != null && !password.trim().equals(""))
        && (username == null || username.trim().equals(""))) {
      throw new MailException(MailException.MISSING_USERNAME);
    }

    this.transport = transport;
    this.session = createMailSession(host, port, username, password);
  }
View Full Code Here

        t.connect();
        t.sendMessage(message, message.getAllRecipients());
        t.close();
      } catch (UnsupportedEncodingException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        throw new MailException(String.format(
            MailException.INVALID_ENCODING, e.getMessage()));
      } catch (MessagingException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
        throw new MailException(String.format(
            MailException.GENERIC_ERROR, e.getMessage()), e);
      } finally {
        transport.clearTemporaryTrustedHosts();
      }
    }
View Full Code Here

*/
public class MailUtils {

  public static boolean validate(Mail email) throws MailException {
    if (email.getText() == null && email.getHtml() == null) {
      throw new MailException(MailException.MISSING_CONTENT);
    } else if (email.getSubject() == null || email.getSubject().equals("")) {
      throw new MailException(MailException.MISSING_SUBJECT);
    } else if (email.getTo().isEmpty() && email.getBcc().isEmpty()
        && email.getCc().isEmpty()) {
      throw new MailException(MailException.MISSING_RECIPIENT);
    } else if (email.getFrom() == null) {
      throw new MailException(MailException.MISSING_SENDER);
    } else {
      String exceptionMessage = null;

      try {
        exceptionMessage = MailException.INVALID_SENDER;
        email.getFrom().validate();

        if (email.getReplyTo() != null) {
          exceptionMessage = MailException.INVALID_REPLYTO;
          email.getReplyTo().validate();
        }

        exceptionMessage = MailException.INVALID_TO;

        for (InternetAddress a : email.getTo()) {
          a.validate();
        }

        exceptionMessage = MailException.INVALID_BCC;

        for (InternetAddress a : email.getBcc()) {
          a.validate();
        }

        exceptionMessage = MailException.INVALID_CC;

        for (InternetAddress a : email.getCc()) {
          a.validate();
        }
      } catch (AddressException ex) {
        throw new MailException(String.format(exceptionMessage, email),
            ex);
      }
    }

    return true;
View Full Code Here

TOP

Related Classes of com.blazebit.mail.MailException

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.