Camel route, unparsed date

244 views Asked by At

i'm using camel route that sends emails with smtp.gmail.com the URI is something like this

 uri="smtps://[email protected]&[email protected]&password=password&debugMode=true&[email protected]&subject=${date:now:yyyyMMdd}"

so i'm expecting to get the current date as Subject , but the date is not parsed and it prints "${date:now:yyyyMMdd}"

2

There are 2 answers

0
Adam Hawkes On BEST ANSWER

I'm not sure you can use the simple expression inside the uri like that. You'd be better off setting the subject and other values in headers.

<route>
  <from uri="direct:example" />
  <setHeader headerName="subject"><simple>${date:now:yyyyMMdd}</simple></setHeader>
  <setHeader headerName="from"><constant>[email protected]</constant></setHeader>
  <setHeader headerName="to"><constant>[email protected]</constant></setHeader>
  <setHeader headerName="username"><constant>[email protected]</constant></setHeader>
  <setHeader headerName="password"><constant>password</constant></setHeader>
  <to uri="smtps://smtp.gmail.com?debugMode=true" />
</route>
0
Ramin Arabbagheri On

You can simply use your URI inside a RecipientList. So

Instead of:

<to uri="smtps://[email protected]&amp;[email protected]&amp;password=password&amp;debugMode=true&amp;[email protected]&amp;subject=${date:now:yyyyMMdd}"/>

Use:

<recipientList>
  <simple>smtps://[email protected]&amp;[email protected]&amp;password=password&amp;debugMode=true&amp;[email protected]&amp;subject=${date:now:yyyyMMdd}</simple>
</recipientList>

Let me know if this works for you.

Read more here: http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html