Thank you again,

What I try to get is to use my own instance of MailComponent and then using
URIs starting by mail://, and also be able to configure some parameters like
the smtp protocol and the email destination.
I've seen that I can configure an endpoint and use it in route.
As you said it's not mandatory to use a JNDI context.

Camel is really interesting!

As soon as I get more experiment with Apache Camel, I will put some articles
on my web site www.odelia-technologies.com/


Here the code that's good:

                CamelContext camelContext = new DefaultCamelContext();
                
                MailComponent mail = new MailComponent();
                camelContext.addComponent("mail", mail);
                
                final MailEndpoint ep = (MailEndpoint)
camelContext.getEndpoint("mail://[EMAIL PROTECTED]");
                ep.getConfiguration().setProtocol("smtp");
                ep.getConfiguration().setDestination("[EMAIL PROTECTED]");
                
                camelContext.addRoutes(new RouteBuilder() {

                    public void configure() {
                        
from("timer:myTimerEvent?fixedRate=true&delay=0&period=1000")
                        .setBody(Builder.constant("Salut !")).to(ep);           
        
                    }
                    
                });
                
                camelContext.start();



James.Strachan wrote:
> 
> On 9/19/07, bgoetzmann <[EMAIL PROTECTED]> wrote:
>>
>> Thank you James,
>>
>> I succeed to send email, using this URI:
>>
>> smtp://[EMAIL PROTECTED]
>>
>> I've seen that you can use of # to define a destination email by look at
>> code source (otherwise it seems that the email [EMAIL PROTECTED] is
>> used.
>>
>>
>> Now I try to use my own MailComponent instance with the scheme "mail";
>> here
>> the code:
>>
>>
>> JndiContext context = new JndiContext();
>>
>> MailComponent mail = new MailComponent();
>> context.bind("mail", mail);
>>
>> CamelContext camelContext = new DefaultCamelContext(context);
>>
>> camelContext.addRoutes(new RouteBuilder() {
>>
>>   public void configure() {
>>     from("timer:myTimerEvent?fixedRate=true&delay=0&period=1000")
>>     .setBody(Builder.constant("Salut
>> !")).to("mail://[EMAIL PROTECTED]@www.com");
>>   }
>>
>> });
> 
> In general that should all work fine; one complication with the Mail
> component is that it supports a few different protocols; pop3, smtp
> and so forth. So if you use, say, "smpt" instead of "mail" in the
> above code (both the URL and the registration in JNDI) it should work
> just fine.
> 
> e.g.
> 
> JndiContext context = new JndiContext();
> 
> MailComponent mail = new MailComponent();
> context.bind("smtp", mail);
> 
> CamelContext camelContext = new DefaultCamelContext(context);
> 
> camelContext.addRoutes(new RouteBuilder() {
> 
>  public void configure() {
>    from("timer:myTimerEvent?fixedRate=true&delay=0&period=1000")
>    .setBody(Builder.constant("Salut
> !")).to("smtp://[EMAIL PROTECTED]@www.com");
>  }
> 
> });
> 
> 
> BTW the use of JNDI or Spring ApplicationContext is an optional
> feature to help you reuse a single registry for configuration; if you
> prefer you can just register components and endpoints directly on the
> CamelContext via addComponent/addSingletonEndpoint.
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Sending-an-email-with-Camel-tf4443341s22882.html#a12796190
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to