Examples of QwertoMailerException


Examples of com.qwertovsky.mailer.errors.QwertoMailerException

  public Sender(String smtpHostName, int smtpPort, final String smtpUser,
      final String smtpPassword, String hostname)
    throws QwertoMailerException, Exception
  {
    if(smtpHostName == null || smtpHostName.length() == 0)
      throw new QwertoMailerException("SMTP server is not specified");
    if(smtpPort == 0)
      smtpPort = 25;
    if(hostname == null)
      hostname = "";
   
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

      , boolean haltOnFailure)
  throws QwertoMailerException, Exception
   
  {
    if(messageContent == null)
      throw new QwertoMailerException("Message is null");
    String charset = messageContent.getCharset();
    Address from = messageContent.getAddressFrom();
    if(from == null)
      throw new QwertoMailerException("From email has not been specified");
 
    if(emailsTo == null || emailsTo.isEmpty())
    {
      throw new QwertoMailerException("Recipients list is empty");
    }
   
    mailProp.put("mail.mime.charset", charset);
   
    //create messages
    ArrayList<Message> messages = new ArrayList<Message>();
    logger.info("Create personal messages");
    badEmails = new ArrayList<String>();
    for(InternetAddress emailTo:emailsTo)
    {
      try
      {
        emailTo.validate();
        Message message = new Message(session);
        makeMessage(message, messageContent);
        message.setRecipient(RecipientType.TO, emailTo);
        messages.add(message);
      } catch(AddressException ae)
      {
        //bad address of recipient
        logger.error("Email " + emailTo.getAddress() + " is incorrect: "
            + ae.getMessage());
        badEmails.add(emailTo.getAddress());
      } catch (MessagingException e)
      {
        logger.error("Message has not been created for "+ emailTo + "("+e.getMessage()+")");
        throw e;
      }
    }
   
    //halt on failure
    if(haltOnFailure && !badEmails.isEmpty())
    {
      throw new QwertoMailerException("Halt on failure");
    }
   
    //send messages
    logger.info("Start sending: " + messages.size() + " messages");
    notSentMessages = new ArrayList<Message>();
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

  public void send(MessageContent messageContent, List<Map<String, String>> personParameters
      , boolean haltOnFailure)
  throws QwertoMailerException, Exception
  {
    if(messageContent == null)
      throw new QwertoMailerException("Message is null");
    String charset = messageContent.getCharset();
    Address from = messageContent.getAddressFrom();
    if(from == null)
      throw new QwertoMailerException("From email has not been specified");
 
    if(personParameters == null || personParameters.isEmpty())
    {
      throw new QwertoMailerException("Recipients list is empty");
    }
   
    mailProp.put("mail.mime.charset", charset);
    Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
        "org.apache.velocity.slf4j.Slf4jLogChute");
    Velocity.setProperty("runtime.log.logsystem.slf4j.name",
      "com.qwertovsky.mailer");
    Velocity.init();
   
    badEmails = new ArrayList<String>();
    badParametersMap = new ArrayList<Map<String, String>>();
   
    //create messages
    ArrayList<Message> messages = new ArrayList<Message>();
   
    logger.info("Create personal messages");
   
    for(Map<String, String> parameters:personParameters)
    {
      //get emails
      Set<InternetAddress> recipients = getRecipientsList(parameters);
      //error if list is empty
      if(recipients == null)
      {
        StringBuilder sb = new StringBuilder();
        Set<String> keys = parameters.keySet();
        for(String key:keys)
        {
          if(sb.length() > 0)
            sb.append(", ");
          sb.append("\"" + parameters.get(key) + "\"");
        }
        logger.error("Recipients list is empty: " + sb.toString());
        continue;
      }
     
      //get attachments
      List<File> attachments = getAttachments(parameters);
     
      //create individual message content
      MessageContent content = new MessageContent(messageContent);
      if(attachments != null && !attachments.isEmpty())
        content.addAttachments(attachments);
      try
      {
        content.setParameters(parameters);
      } catch (QwertoMailerException qme)
      {
        String errorMessage = "Message has not been created (" + qme.getMessage() + ") for: ";
        StringBuilder sb = new StringBuilder();
        Set<String> headers = parameters.keySet();
        for(String header:headers)
        {
          if(sb.length() > 0)
            sb.append(", ");
          sb.append("\"" + parameters.get(header) + "\"");
        }
        logger.error(errorMessage + sb.toString());
        badParametersMap.add(parameters);
        continue;
      }
     
     
      Message message = new Message(session);
      try
      {
        makeMessage(message, content);
        message.setRecipients(RecipientType.TO, recipients.toArray(new InternetAddress[0]));
      } catch (MessagingException e)
      {
        logger.error("Message has not been created for "
            + recipients.toArray() + "("+e.getMessage()+")");
        throw e;
      }
      message.setParameters(parameters);
      messages.add(message);
    }
   
    //halt on failure
    if(haltOnFailure && (!badEmails.isEmpty() || !badParametersMap.isEmpty()))
      throw new QwertoMailerException("Halt on failure");
   
    //send messages
    logger.info("Start sending");
    notSentMessages = new ArrayList<Message>();
    sentMessages = new ArrayList<Message>();
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

    Message message = new MimeMessage(mailSession, EMLFileIStream);
    content = message.getContent();
    contentType = message.getContentType();
    subject = message.getSubject();
    if(subject == null || subject.equals(""))
      throw new QwertoMailerException("Subject can't be null or empty");
    //get charset
    ContentType ct = new ContentType(contentType);
    charset = ct.getParameter("charset");
    if(charset == null)
      charset = "UTF-8";
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

  public MessageContent(String content, String contentType, String subject, String charset)
    throws QwertoMailerException
  {
    //not allow content with no body parts
    if(content == null || content.equals(""))
      throw new QwertoMailerException("Content can't be null or empty");
    this.content = content;
   
    //not allow message with no subject
    if(subject == null || subject.equals(""))
      throw new QwertoMailerException("Subject can't be null or empty");
    this.subject = subject;
   
    //set default charset
    if(charset == null || charset.length() == 0)
      charset = "utf-8";
    this.charset = charset;
   
    if(contentType == null || contentType.length() == 0)
      throw new QwertoMailerException("Content type can't be null or empty");
   
    try
    {
      ContentType ct = new ContentType(contentType);
      this.contentType = ct.getBaseType() + "; charset=" + charset;
      ct = new ContentType(this.contentType);
    } catch (ParseException pe)
    {
      //specify that the problem relates to the ContentType
      throw new QwertoMailerException("Bad ContentType: " + pe.getMessage());
    }
  }
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

   * @throws QwertoMailerException Subject can't be null or empty
   */
  public void setSubject(String subject) throws QwertoMailerException
  {
    if(subject == null || subject.equals(""))
      throw new QwertoMailerException("Subject can't be null or empty");
    this.subject = subject;
  }
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

    throws QwertoMailerException
    , Exception
    , UnsupportedEncodingException
  {
    if(email == null || email.length() == 0)
      throw new QwertoMailerException ("Email in FROM can't be null or empty");
    addressFrom = new InternetAddress(email, person, charset);
    addressFrom.validate();
  }
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

   */
  protected String addInlineAttachment(String path)
    throws Exception, IOException, QwertoMailerException
  {
    if(path == null || path.length() == 0)
      throw new QwertoMailerException("Inline image url can't be null or empty");
    if(content instanceof Multipart
        && ((Multipart)content).getContentType().startsWith("multipart/mixed"))
    {
      //get and replace html part of message
      Object body = ((Multipart)content).getBodyPart(0).getContent();
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

  public void setParameters(String[] headers, String[] parameters)
    throws Exception
    , QwertoMailerException
  {
    if(headers == null || headers.length == 0)
      throw new QwertoMailerException("Headers can't be null or have length equal to 0");
    if(parameters == null || parameters.length == 0)
      throw new QwertoMailerException("Parameters can't be null or have length equal to 0");
    if(parameters.length < headers.length)
      throw new QwertoMailerException("Parameters must be not less then headers");
   
    //from arrays to map
    Map<String, String> parameterMap = new HashMap<String, String>(headers.length);
    for(int i = 0; i < headers.length; i++)
    {
View Full Code Here

Examples of com.qwertovsky.mailer.errors.QwertoMailerException

  public void setParameters(Map<String, String> parameters)
    throws Exception
    , QwertoMailerException
  {
    if(parameters == null || parameters.size() == 0)
      throw new QwertoMailerException("Parameters can't be null or have length equal to 0");
   
    Set<String> headers = parameters.keySet();
   
    VelocityContext context = new VelocityContext();
    for(String header:headers)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.