You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Er1c <Er...@Peters.org> on 2008/02/03 16:04:56 UTC

Howto get an SMTP Endpoint to dynamically send to a Header Value

I'm trying to figure out an easy way to use Spring XML (well anything really)
to specify the delivery address of an SMTP endpoint from a header

This is how I have the "generic" SMTP delivery:
    <route>
      <from uri="activemq:queue:OutgoingEmail" />
      <to uri="smtp://localhost" />
    </route>

I have a header set called "deliver_to" that has the email address I'd want
to email.
Ideally, I would like to specify the from information (at least from an
envelope standpoint) dyanmically as well - but I've already create standard
evelope things like From:, Reply-To:, Subject: in the message being routed
to the OutgoingEmail queue.


Thanks,

Eric
-- 
View this message in context: http://www.nabble.com/Howto-get-an-SMTP-Endpoint-to-dynamically-send-to-a-Header-Value-tp15254242s22882p15254242.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by James Strachan <ja...@gmail.com>.
On 06/02/2008, Er1c <Er...@peters.org> wrote:
>
> Going back to a java version I think I got something working:
>
>                 from("activemq:queue:OutgoingEmail").
>                         recipientList(el("smtp://localhost#${in.headers.deliver_to}"));
>
> Tailing the mail.log it looks like the delivery is being sent to the correct
> locations!

Awesome! :)

> I'd love to figure out howto do this in Spring XML - but I think I figured
> out the growing pains of compiling this with Maven/adding the
> dependencies/getting JUEL/etc.

Yeah - I think classpaths are probably the biggest issue of working
with Camel...

I've not tried it, but would the following work...

  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="activemq:queue:OutgoingEmail"/>
      <recipientList>
        <el>smtp://localhost#${in.headers.deliver_to}</el>
      </recipientList>
    </route>
  </camelContext>

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by Er1c <Er...@Peters.org>.
Going back to a java version I think I got something working:

		from("activemq:queue:OutgoingEmail").
			recipientList(el("smtp://localhost#${in.headers.deliver_to}")); 

Tailing the mail.log it looks like the delivery is being sent to the correct
locations!

I'd love to figure out howto do this in Spring XML - but I think I figured
out the growing pains of compiling this with Maven/adding the
dependencies/getting JUEL/etc.

-Eric


Er1c wrote:
> 
> Route[ [From[activemq:queue:OutgoingEmail]] -> [RecipientList[ null]]]]
> 
> using:
>     <route>
>       <from uri="activemq:queue:OutgoingEmail" />
>         <recipientList>
>           <recipients>
>             <el>"smtp://localhost#${in.headers.deliver_to}"</el>
>           </recipients>
>         </recipientList>
>     </route>
> 
> If I comment out the inner <recipients> I get:
>  Route[ [From[activemq:queue:OutgoingEmail]] -> [RecipientList[
> elExpression["smtp://localhost#${in.headers.deliver_to}"]]]]]
> 
> 
>     <route>
>       <from uri="activemq:queue:OutgoingEmail" />
>         <recipientList>
> <!--          <recipients>-->
>             <el>"smtp://localhost#${in.headers.deliver_to}"</el>
> <!--          </recipients>-->
>         </recipientList>
>     </route>
> 
> 
> I'm not actually seeing any email delivered though (nothing in the
> /var/log/mail.log as even attempted)...and even when I have debug enabled
> I'm not able to see routing errors printed anywhere when messages get
> added to OutgoingEmail...
> 
> What's the best way to see what ActiveMQ is trying to route it to?
> 
> If I take out the quotes around
> <el>"smtp://localhost#${in.headers.deliver_to}"</el> it throws a "broken
> pipe" issue
> 
> 
> Thanks,
> 
> Eric
> 
> 
> 
> James.Strachan wrote:
>> 
>> Apologies, I made a typo...
>> 
>> On 05/02/2008, Er1c <Er...@peters.org> wrote:
>>>
>>> Thanks for the response, I hadn't considered the RecipientList
>>> approach...
>>>
>>> I tried something like:
>>>
>>>     <route>
>>>       <from uri="activemq:queue:OutgoingEmail" />
>>>         <recipientList>
>>>           <recipients>
>>>             <el>"smtp://localhost#${in.header.deliver_to}"</el>
>> 
>> 
>> ${in.headers.deliver_to}
>> 
>> i.e. its the plural headers which maps to the Message.getHeaders() method
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source Integration
>> http://open.iona.com
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Howto-get-an-SMTP-Endpoint-to-dynamically-send-to-a-Header-Value-tp15254242s22882p15306716.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by Er1c <Er...@Peters.org>.
Route[ [From[activemq:queue:OutgoingEmail]] -> [RecipientList[ null]]]]

using:
    <route>
      <from uri="activemq:queue:OutgoingEmail" />
        <recipientList>
          <recipients>
            <el>"smtp://localhost#${in.headers.deliver_to}"</el>
          </recipients>
        </recipientList>
    </route>

If I comment out the inner <recipients> I get:
 Route[ [From[activemq:queue:OutgoingEmail]] -> [RecipientList[
elExpression["smtp://localhost#${in.headers.deliver_to}"]]]]]


    <route>
      <from uri="activemq:queue:OutgoingEmail" />
        <recipientList>
<!--          <recipients>-->
            <el>"smtp://localhost#${in.headers.deliver_to}"</el>
<!--          </recipients>-->
        </recipientList>
    </route>


I'm not actually seeing any email delivered though (nothing in the
/var/log/mail.log as even attempted)...and even when I have debug enabled
I'm not able to see routing errors printed anywhere when messages get added
to OutgoingEmail...

What's the best way to see what ActiveMQ is trying to route it to?

If I take out the quotes around
<el>"smtp://localhost#${in.headers.deliver_to}"</el> it throws a "broken
pipe" issue


Thanks,

Eric



James.Strachan wrote:
> 
> Apologies, I made a typo...
> 
> On 05/02/2008, Er1c <Er...@peters.org> wrote:
>>
>> Thanks for the response, I hadn't considered the RecipientList
>> approach...
>>
>> I tried something like:
>>
>>     <route>
>>       <from uri="activemq:queue:OutgoingEmail" />
>>         <recipientList>
>>           <recipients>
>>             <el>"smtp://localhost#${in.header.deliver_to}"</el>
> 
> 
> ${in.headers.deliver_to}
> 
> i.e. its the plural headers which maps to the Message.getHeaders() method
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Howto-get-an-SMTP-Endpoint-to-dynamically-send-to-a-Header-Value-tp15254242s22882p15306684.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by James Strachan <ja...@gmail.com>.
Apologies, I made a typo...

On 05/02/2008, Er1c <Er...@peters.org> wrote:
>
> Thanks for the response, I hadn't considered the RecipientList approach...
>
> I tried something like:
>
>     <route>
>       <from uri="activemq:queue:OutgoingEmail" />
>         <recipientList>
>           <recipients>
>             <el>"smtp://localhost#${in.header.deliver_to}"</el>


${in.headers.deliver_to}

i.e. its the plural headers which maps to the Message.getHeaders() method

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by Er1c <Er...@Peters.org>.
Thanks for the response, I hadn't considered the RecipientList approach...

I tried something like:

    <route>
      <from uri="activemq:queue:OutgoingEmail" />
        <recipientList>
          <recipients>
            <el>"smtp://localhost#${in.header.deliver_to}"</el>
          </recipients>
        </recipientList>
    </route>

But when I look at the log file I'm still seeing OutgoingEmail =>
RecipientList [Null]

Even the example in the Design Pattern docs - will show me a null
RecipientList

<camelContext id="buildDynamicRecipientList"
xmlns="http://activemq.apache.org/camel/schema/spring">
  <route>
    <from uri="seda:a"/>
    <recipientList>
      <recipients>
        <header name="foo"/>
      </recipients>
    </recipientList>
  </route>
</camelContext>

I made sure to put camel-juel-1.2.0 into my lib directory - would there be
others I need to add too?

-Eric


James.Strachan wrote:
> 
> On 03/02/2008, Er1c <Er...@peters.org> wrote:
>>
>> I'm trying to figure out an easy way to use Spring XML (well anything
>> really)
>> to specify the delivery address of an SMTP endpoint from a header
>>
>> This is how I have the "generic" SMTP delivery:
>>     <route>
>>       <from uri="activemq:queue:OutgoingEmail" />
>>       <to uri="smtp://localhost" />
>>     </route>
>>
>> I have a header set called "deliver_to" that has the email address I'd
>> want
>> to email.
>> Ideally, I would like to specify the from information (at least from an
>> envelope standpoint) dyanmically as well - but I've already create
>> standard
>> evelope things like From:, Reply-To:, Subject: in the message being
>> routed
>> to the OutgoingEmail queue.
> 
> I think what you are asking for is that the output URI be dynamic made
> up from some expression using the message headers / body right?
> 
> If so then this sounds like the dynamic recipient list pattern...
> 
> http://activemq.apache.org/camel/recipient-list.html
> 
> e.g. using EL something like
> 
> from("activemq:SomeQueue").recipientList().el("smtp://${in.header.to}@localhost");
> 
> i.e. using an EL expression to create the to URI
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Howto-get-an-SMTP-Endpoint-to-dynamically-send-to-a-Header-Value-tp15254242s22882p15291023.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Howto get an SMTP Endpoint to dynamically send to a Header Value

Posted by James Strachan <ja...@gmail.com>.
On 03/02/2008, Er1c <Er...@peters.org> wrote:
>
> I'm trying to figure out an easy way to use Spring XML (well anything really)
> to specify the delivery address of an SMTP endpoint from a header
>
> This is how I have the "generic" SMTP delivery:
>     <route>
>       <from uri="activemq:queue:OutgoingEmail" />
>       <to uri="smtp://localhost" />
>     </route>
>
> I have a header set called "deliver_to" that has the email address I'd want
> to email.
> Ideally, I would like to specify the from information (at least from an
> envelope standpoint) dyanmically as well - but I've already create standard
> evelope things like From:, Reply-To:, Subject: in the message being routed
> to the OutgoingEmail queue.

I think what you are asking for is that the output URI be dynamic made
up from some expression using the message headers / body right?

If so then this sounds like the dynamic recipient list pattern...

http://activemq.apache.org/camel/recipient-list.html

e.g. using EL something like

from("activemq:SomeQueue").recipientList().el("smtp://${in.header.to}@localhost");

i.e. using an EL expression to create the to URI

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com