camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nadtech <>
Subject Using the alternativeBodyHeader
Date Thu, 02 Jul 2015 20:00:34 GMT
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"/>
			<to uri="velocity://email-html.vm" />				
			<to ref="smtpServer" />

My bean is autowired and the method looks like this:

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

        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("", 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");
	return stringWriter.toString();

I have 2 templates.     
            ${greeting} This is a system generated email. Please do not
reply to this email.

     ${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:
Sent from the Camel - Users mailing list archive at

View raw message