I'm new to camel ... Trying to send a multipart/alternative (text/plain and
text/html) using Spring, Camel, and Velocity.

In my route I have the following snippet:
                        <setHeader headerName="alternativeBodyHeader">
                                <method bean="eDeliveryProcessor" 
method="plainTemplateAsString"/>
                        </setHeader>    
                        <to uri="velocity://email-html.vm" />                   
        
                        <to ref="smtpServer" />

My bean is autowired and the method looks like this:

        @Handler
        public String plainTemplateAsString(Exchange exchange, 
                        @Headers Map<String, Object> headers, 
@Header("edeliveryId") String
edeliveryId, 
                        @Body DeliveryRequest request) throws AddressException {
                
        VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        ve.setProperty("classpath.resource.loader.class",
ClasspathResourceLoader.class.getName());
        ve.init();
        

        Template template = ve.getTemplate("email-plain.vm");
        Context context = new VelocityContext();
        context.put("dateTool", new DateTool());
        
        Email email = (Email) request.getType();
        //context.put("body.type.body", email.getBody());
        //context.put("body.id", edeliveryId);
        context.put("greeting", "hello");
        context.put("person", "John Doe");


        StringWriter stringWriter = new StringWriter();
        template.merge(context, stringWriter);

        exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/html");
        exchange.getIn().setHeader("alternativeBodyHeader",
stringWriter.toString());
        
        System.out.println(stringWriter.toString());
        
        return stringWriter.toString();
        }

I have 2 templates.     
email-html.vm:
     <html>
     <body>
        <div><em>
            ${greeting} This is a system generated email. Please do not
reply to this email.
        </em></div>
     </body>
     </html>

email-plain.vm:
     ${greeting} ${person} This is a system generated email.  Please do not
reply to this email. 

I setup Outlook 2007 to receive plain text.  When the code runs I receive
email-html.vm converted to plain text.  I was expecting the content of
email-plain.vm version instead.

Advice would be much appreciated!  Thanks.




--
View this message in context: 
http://camel.465427.n5.nabble.com/Using-the-alternativeBodyHeader-tp5768828.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to