Announcement Announcement Module
Collapse
No announcement yet.
Can a view be sent via email? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2devnull
    started a topic Can a view be sent via email?

    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.

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

    Leave a comment:


  • 2devnull
    replied
    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);

    Leave a comment:


  • Rod Johnson
    replied
    You might be able to override VelocityView's mergeTemplate() method to merge the template to a separate stream.

    Leave a comment:

Working...
X