Package org.springframework.mail

Examples of org.springframework.mail.MailPreparationException


                final StringWriter subjectTextWriter = new StringWriter();
               
                try {
                  subjectTextTemplate.process(map, subjectTextWriter);
                } catch (TemplateException e) {
                    throw new MailPreparationException("Can't generate Subject Text", e);
                }        
                mimeMessage.setSubject(subjectTextWriter.toString());     
               
                //
                // Create a "text" Multipart message
                //
               
                Template bodyTextTemplate = configuration.getTemplate(bodyTemplatePrefix);
                final StringWriter bodyTextWriter = new StringWriter();
               
               
                try {
                  bodyTextTemplate.process(map, bodyTextWriter);
                } catch (TemplateException e) {
                    throw new MailPreparationException("Can't generate Body Text", e);
                }
                mimeMessage.setText(bodyTextWriter.toString());
               

/*                // @TODO - This part handles sending an attachement
View Full Code Here


    }
    catch (MessagingException ex) {
      throw new MailParseException(ex);
    }
    catch (IOException ex) {
      throw new MailPreparationException(ex);
    }
    catch (Exception ex) {
      throw new MailPreparationException(ex);
    }
  }
View Full Code Here

    try {
      helper.setSubject(context.getSubject());
      helper.setText(context.getContent());
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to compose simple mail message: " + me.getMessage(), me);
    }
  }
View Full Code Here

      text.close();

      helper.setText(text.toString(), context.isHtmlTemplate());
    }
    catch(final IOException ioe) {
      throw new MailPreparationException("Unable to compose templated mail content due to an I/O exception: "
          + ioe.getMessage(), ioe);
    }
    catch(final VelocityException ve) {
      throw new MailPreparationException("Unable to compose templated mail content due to a Velocity exception: "
          + ve.getMessage(), ve);
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("unable to compose templated mail content due to a messaging exception: "
          + me.getMessage(), me);
    }

  }
View Full Code Here

    MimeMessageHelper helper;
    try {
      helper = new MimeMessageHelper(mimeMessage, true, context.getEncoding());
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to create the mime message helper", me);
    }

    // apply the routing
    final MailRouting mailRouting = context.getRouting();
    if(mailRouting == null) {
      throw new MailPreparationException("No email routing specified.");
    }
    try {
      // sender
      final NameEmail sender = mailRouting.getSender();
      if(sender != null) {
        helper.setFrom(sender.getEmailAddress(), sender.getName());
      }

      List<NameEmail> list;

      // recipients
      list = mailRouting.getRecipients();
      if(list.isEmpty()) {
        throw new MailPreparationException("No email recipients specified");
      }
      for(final NameEmail email : list) {
        helper.addTo(email.getEmailAddress(), email.getName());
      }

      // ccs
      list = mailRouting.getCcList();
      if(list != null && list.size() > 0) {
        for(final NameEmail email : list) {
          helper.addCc(email.getEmailAddress(), email.getName());
        }
      }

      // bccs
      list = mailRouting.getBccList();
      if(list != null && list.size() > 0) {
        for(final NameEmail email : list) {
          helper.addBcc(email.getEmailAddress(), email.getName());
        }
      }

    }
    catch(final UnsupportedEncodingException uee) {
      throw new MailPreparationException("Unsupported mime message encoding: " + uee.getMessage(), uee);
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Trouble performing the initial mime message compose:" + me.getMessage(), me);
    }

    // do implemenation specific composing
    composeImpl(helper, context);

    // add attachments
    try {
      final List<Attachment> attachments = context.getAttachments();
      if(!attachments.isEmpty()) {
        for(final Attachment attachment : attachments) {
          helper.addAttachment(attachment.getName(), attachment.getDataSource());
        }
      }

    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to add email attachments:" + me.getMessage(), me);
    }

    return helper.getMimeMessage();
  }
View Full Code Here

    MimeMessageHelper helper;
    try {
      helper = new MimeMessageHelper(mimeMessage, true, context.getEncoding());
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to create the mime message helper", me);
    }

    // apply the routing
    final MailRouting mailRouting = context.getRouting();
    if(mailRouting == null) {
      throw new MailPreparationException("No email routing specified.");
    }
    try {
      // sender
      final NameEmail sender = mailRouting.getSender();
      if(sender != null) {
        helper.setFrom(sender.getEmailAddress(), sender.getName());
      }

      List<NameEmail> list;

      // recipients
      list = mailRouting.getRecipients();
      if(list.isEmpty()) {
        throw new MailPreparationException("No email recipients specified");
      }
      for(final NameEmail email : list) {
        helper.addTo(email.getEmailAddress(), email.getName());
      }

      // ccs
      list = mailRouting.getCcList();
      if(list != null && list.size() > 0) {
        for(final NameEmail email : list) {
          helper.addCc(email.getEmailAddress(), email.getName());
        }
      }

      // bccs
      list = mailRouting.getBccList();
      if(list != null && list.size() > 0) {
        for(final NameEmail email : list) {
          helper.addBcc(email.getEmailAddress(), email.getName());
        }
      }

    }
    catch(final UnsupportedEncodingException uee) {
      throw new MailPreparationException("Unsupported mime message encoding: " + uee.getMessage(), uee);
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Trouble performing the initial mime message compose:" + me.getMessage(), me);
    }

    // do implemenation specific composing
    composeImpl(helper, context);

    // add attachments
    try {
      final List<Attachment> attachments = context.getAttachments();
      if(!attachments.isEmpty()) {
        for(final Attachment attachment : attachments) {
          helper.addAttachment(attachment.getName(), attachment.getDataSource());
        }
      }

    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to add email attachments:" + me.getMessage(), me);
    }

    return helper.getMimeMessage();
  }
View Full Code Here

    try {
      helper.setSubject(context.getSubject());
      helper.setText(context.getContent());
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("Unable to compose simple mail message: " + me.getMessage(), me);
    }
  }
View Full Code Here

      text.close();

      helper.setText(text.toString(), context.isHtmlTemplate());
    }
    catch(final IOException ioe) {
      throw new MailPreparationException("Unable to compose templated mail content due to an I/O exception: "
          + ioe.getMessage(), ioe);
    }
    catch(final VelocityException ve) {
      throw new MailPreparationException("Unable to compose templated mail content due to a Velocity exception: "
          + ve.getMessage(), ve);
    }
    catch(final MessagingException me) {
      throw new MailPreparationException("unable to compose templated mail content due to a messaging exception: "
          + me.getMessage(), me);
    }

  }
View Full Code Here

    }
    catch (MessagingException ex) {
      throw new MailParseException(ex);
    }
    catch (IOException ex) {
      throw new MailPreparationException(ex);
    }
    catch (Exception ex) {
      throw new MailPreparationException(ex);
    }
  }
View Full Code Here

    }
    catch (MessagingException ex) {
      throw new MailParseException(ex);
    }
    catch (IOException ex) {
      throw new MailPreparationException(ex);
    }
    catch (Exception ex) {
      throw new MailPreparationException(ex);
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.mail.MailPreparationException

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.