Results 1 to 4 of 4

Thread: Can a view be sent via email?

  1. #1

    Default Can a view be sent via email?

    I have a view that is shown to the user done in Velocity. Is there any way in Spring to send this exact view via email at the same time in the same format.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    You might be able to override VelocityView's mergeTemplate() method to merge the template to a separate stream.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3

    Default

    Thanks Rod,
    I had done just that and it all works now. Thanks for the suggestion. For the benefit of others, here is the actual code:

    sw is a StringWriter.

    Code:
    try {
    
    					mailSender.send(new MimeMessagePreparator() {
    						public void prepare(MimeMessage mimeMessage) throws MessagingException {
    							MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
    							message.setFrom(from);
    							if (!to.equals("") && StringUtils.commaDelimitedListToStringArray(to).length > 0)
    								message.setTo(StringUtils.commaDelimitedListToStringArray(to));
    							if (!cc.equals("") && StringUtils.commaDelimitedListToStringArray(cc).length > 0)
    								message.setCc(StringUtils.commaDelimitedListToStringArray(cc));
    							if (!bcc.equals("") && StringUtils.commaDelimitedListToStringArray(bcc).length > 0)
    								message.setBcc(StringUtils.commaDelimitedListToStringArray(bcc));
    							message.setSubject(subject + " - " + request.getServerName()+" ("+request.getRemoteAddr()+")");
    							
    							String mailBody = sw.toString();
    							try {
    								mailBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/WEB-INF/velocity/en_EN/errorview.vm", "UTF-8", myModel);
    							} catch (VelocityException ve) {
    								logger.error("Exception in VelocityEngineUtils - mail not sent");
    							}
    			
    							message.setText(mailBody, true);
    							logger.error("Sent exception email to: "+to+" (cc: "+cc+")");
    							
    						}
    					});
    				} catch (Exception e) {
    					logger.error("Exception occured sending exception email - " + e.getMessage());
    				}
    
    return new ModelAndView("errorview", "model", myModel);

  4. #4
    Join Date
    Aug 2004
    Location
    Athens, GA
    Posts
    20

    Default

    How would one go about doing this with Tiles JSTL/JSP views?

Similar Threads

  1. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  2. Replies: 0
    Last Post: Aug 29th, 2005, 03:23 PM
  3. PageCompononentListener Hooks...JIRA issue?
    By amcauley in forum Swing
    Replies: 9
    Last Post: Apr 15th, 2005, 06:10 AM
  4. Content Provider vs View Model
    By Martin Kersten in forum Swing
    Replies: 21
    Last Post: Mar 10th, 2005, 02:25 PM
  5. refreshing the view
    By Jurijus Jarmakas in forum Swing
    Replies: 2
    Last Post: Feb 8th, 2005, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •