You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by gmh <go...@gmail.com> on 2015/05/13 21:58:05 UTC

how to get subject and body for mail from a properties file

Hi,
I am using Camel mail to send an email when something happens in a rabbitmq
queue.
I have all of my properties in a properties file.
I have the propertyplaceholder defined before camel context:

  <context:property-placeholder ignore-resource-not-found="true"
location="classpath:xxx"

Below is my route:
<route id="ActionProcessor:direct:email">
            <from uri="direct:email"/>
            <setHeader headerName="subject">
                <constant>Hello</constant>
            </setHeader>
            <setHeader headerName="contentType">
                <constant>text/plain;charset=UTF-8</constant>
            </setHeader>
            <setBody>
                <constant>Test</constant>
            </setBody>
            <to ref="uri"/>
        </route>
The question is how do I read the values from the below properties and
populate the body and subject?

some.processor.consumer.camel.email.body=Test
some.processor.consumer.camel.email.subject=Hello
Thanks,
Gordon



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to get subject and body for mail from a properties file

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use the properties-location function from simple to lookup a properties
http://camel.apache.org/simple

If you are using and older Camel then the function is named
properties. But its all explained on that simple docs.




On Wed, May 13, 2015 at 9:58 PM, gmh <go...@gmail.com> wrote:
> Hi,
> I am using Camel mail to send an email when something happens in a rabbitmq
> queue.
> I have all of my properties in a properties file.
> I have the propertyplaceholder defined before camel context:
>
>   <context:property-placeholder ignore-resource-not-found="true"
> location="classpath:xxx"
>
> Below is my route:
> <route id="ActionProcessor:direct:email">
>             <from uri="direct:email"/>
>             <setHeader headerName="subject">
>                 <constant>Hello</constant>
>             </setHeader>
>             <setHeader headerName="contentType">
>                 <constant>text/plain;charset=UTF-8</constant>
>             </setHeader>
>             <setBody>
>                 <constant>Test</constant>
>             </setBody>
>             <to ref="uri"/>
>         </route>
> The question is how do I read the values from the below properties and
> populate the body and subject?
>
> some.processor.consumer.camel.email.body=Test
> some.processor.consumer.camel.email.subject=Hello
> Thanks,
> Gordon
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: how to get subject and body for mail from a properties file

Posted by akoufoudakis <ak...@gmail.com>.
Hello, Gordon!

I would do it like this.


<camelContext>
<propertyPlaceholder id="emailProps" location="classpath:xxx"/>
<route id="ActionProcessor:direct:email">
            <from uri="direct:email"/>
            <setHeader headerName="subject">
               
<constant>{{some.processor.consumer.camel.email.subject}}</constant>
            </setHeader>
            <setHeader headerName="contentType">
                <constant>text/plain;charset=UTF-8</constant>
            </setHeader>
            <setBody>
               
<constant>{{some.processor.consumer.camel.email.body}}</constant>
            </setBody>
            <to ref="uri"/>
        </route>
</camelContext>

If you want to keep your property file visible in your whole spring context,
then I would do a trick like:

 <context:property-placeholder ignore-resource-not-found="true"
location="classpath:xxx" id="props"/>
   <propertyPlaceholder id="myProps" location="ref:props"/>
   ......
<camelContext>


</camelContext>


For more information you can always go to
http://camel.apache.org/properties.html




--
View this message in context: http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080p5767095.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to get subject and body for mail from a properties file

Posted by Reji Mathews <co...@gmail.com>.
Will this code snippet help you.

  <from uri="seda:ECPE_EmailAlert_BrokerDown"/>

     <setHeader headerName="to">
          <simple>{{alertEmailTo}}</simple>
        </setHeader>
        <setHeader headerName="CC">
            <simple>{{alertEmailCC}}</simple>
        </setHeader>
        <setHeader headerName="from">
            <constant>no_reply@server.com</constant>
        </setHeader>
        <setHeader headerName="subject">
            <simple>{{amqAlertMailSubject}}</simple>
        </setHeader>
        <setBody>
           <constant> Hi this is the body of the email
        </constant>
        </setBody>
        <setHeader headerName="contentType">
            <constant>text/plain</constant>
        </setHeader>

    <to uri="smtp:mailserver.local?mapMailMessage=true"/>
    </route>

On Fri, May 15, 2015 at 1:04 PM, Mukundha Reddy <v....@wipro.com> wrote:

> You can use the below format for getting the properties from property file,
> <route id="ActionProcessor:direct:email">
>             <from uri="direct:email"/>
>             <setHeader headerName="subject">
>
> <simple>${some.processor.consumer.camel.email.subject}</simple>
>             </setHeader>
>             <setHeader headerName="contentType">
>                 <constant>text/plain;charset=UTF-8</constant>
>             </setHeader>
>             <setBody>
>
> <simple>${some.processor.consumer.camel.email.body}</simple>
>             </setBody>
>             <to ref="uri"/>
>         </route>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080p5767133.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: how to get subject and body for mail from a properties file

Posted by Mukundha Reddy <v....@wipro.com>.
You can use the below format for getting the properties from property file,
<route id="ActionProcessor:direct:email">
            <from uri="direct:email"/>
            <setHeader headerName="subject">
               
<simple>${some.processor.consumer.camel.email.subject}</simple>
            </setHeader>
            <setHeader headerName="contentType">
                <constant>text/plain;charset=UTF-8</constant>
            </setHeader>
            <setBody>
                <simple>${some.processor.consumer.camel.email.body}</simple>
            </setBody>
            <to ref="uri"/>
        </route>




--
View this message in context: http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080p5767133.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to get subject and body for mail from a properties file

Posted by Mukundha Reddy <v....@wipro.com>.
<route id="ActionProcessor:direct:email">
            <from uri="direct:email"/>
            <setHeader headerName="subject">
               
<simple>${property.some.processor.consumer.camel.email.subject}</simple>
            </setHeader>
            <setHeader headerName="contentType">
                <constant>text/plain;charset=UTF-8</constant>
            </setHeader>
            <setBody>
               
<simple>${property.some.processor.consumer.camel.email.body}</simple>
            </setBody>
            <to ref="uri"/>
        </route>



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-get-subject-and-body-for-mail-from-a-properties-file-tp5767080p5767129.html
Sent from the Camel - Users mailing list archive at Nabble.com.