You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by tamil13 <ta...@gmail.com> on 2013/01/08 14:28:49 UTC

camel-mail

Hi. I am new to camel. just finished studying 'camel in action' book. but
There is no mail configuration information in it. Using camel, I want to
send a mail using *smtp* component. I tried everything as much as possible.
but There is no progress.
All I need is I want to create a new message, setting properties,
customizing message body and send it using camel smtp component.

I tried following coding.

ProducerTemplate template;
Map<String, Object> map = new HashMap<String, Object>();
map.put("To", "davsclaus@apache.org");
map.put("From", "jstrachan@apache.org");
map.put("Subject", "Camel rocks");

String body = "Hello Claus.\nYes it does.\n\nRegards James.";
template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);

I am getting null pointer exception in template.sendBodyAndHeaders() method.
when I run above code.


Thanks in advance...



--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

Posted by tamil13 <ta...@gmail.com>.
Thank you claus.. As you mentioned, after we added template =
camelContext.createProducerTemplate();.
It is working :-)



--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725131.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

Posted by tamil13 <ta...@gmail.com>.
Ok Claus.. Thanks for your information :-)



--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725294.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

Posted by nickerox <ma...@tiscali.it>.
It works adding "to" property. Many thx



--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5732817.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

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

If you see any exception then that may have details that can lead you
to what is wrong etc. And make sure your username and password is
correct.

Also you need to set a header with the "to" eg with the email to who
is to receive the email.
setHeader("to", constant("someone@somewhere.com"))



On Sat, May 18, 2013 at 7:04 PM, nickerox <ma...@tiscali.it> wrote:
> Hi Claus,
>
> I`m testing this simple java code:
>
> CamelContext ctx = new DefaultCamelContext();
>
>                 ctx.addRoutes(new RouteBuilder() {
>
>                         @Override
>                         public void configure() throws Exception {
>
>                                 from("direct:mail").
>                                  setHeader("subject", constant("Apache camel test"))
>                                 .setHeader("From", constant("test@virgilio.it"))
>                                 .to("smtp://username@virgilio.it?password=****");
>                         }
>                 });
>
>                 ctx.start();
>
>                 Endpoint endpoint = ctx.getEndpoint("direct:mail");
>
>                 ProducerTemplate p = new DefaultProducerTemplate(ctx, endpoint);
>                 p.start();
>                 p.sendBody("Hello!");
>                 System.out.println("Sent!");
>                 p.stop();
>                 ctx.stop();
>
>
> receiving this response: Could not connect to SMTP host: virgilio.it, port:
> 25 (right, because SMTP server is out.virgilio.it);
> If i substitute the endpoint with
> "smtp://username@out.virgilio.it?password=****"
>  I get the right AddressFailedException.
> So, please, could you help me to understand my error or if i have missed any
> properties?
> Thx in advance
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5732800.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel-mail

Posted by nickerox <ma...@tiscali.it>.
Hi Claus,

I`m testing this simple java code:

CamelContext ctx = new DefaultCamelContext();

		ctx.addRoutes(new RouteBuilder() {

			@Override
			public void configure() throws Exception {

				from("direct:mail").
				 setHeader("subject", constant("Apache camel test"))
				.setHeader("From", constant("test@virgilio.it"))
				.to("smtp://username@virgilio.it?password=****");
			}
		});
		
		ctx.start();
		
		Endpoint endpoint = ctx.getEndpoint("direct:mail");
		
		ProducerTemplate p = new DefaultProducerTemplate(ctx, endpoint);
		p.start();
		p.sendBody("Hello!");
		System.out.println("Sent!");
		p.stop();
		ctx.stop(); 


receiving this response: Could not connect to SMTP host: virgilio.it, port:
25 (right, because SMTP server is out.virgilio.it);
If i substitute the endpoint with 
"smtp://username@out.virgilio.it?password=****"
 I get the right AddressFailedException.
So, please, could you help me to understand my error or if i have missed any
properties?
Thx in advance




--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5732800.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jan 10, 2013 at 3:53 PM, tamil13 <ta...@gmail.com> wrote:
> It is working now. Can we config below coding in camel-context.xml also?
>

What do you mean?

The code below is not a Camel route (which you can configure in XML) but code
that sends a message to a Camel endpoint using the producer template.

And for that you need real Java code to do that.


> ProducerTemplate template;
> template = context.createProducerTemplate();
> Map<String, Object> map = new HashMap<String, Object>();
> map.put("To", "davsclaus@apache.org");
> map.put("From", "jstrachan@apache.org");
> map.put("Subject", "Camel rocks");
>
> String body = "Hello Claus.\nYes it does.\n\nRegards James.";
> template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
>
> Thanks in advance.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725286.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel-mail

Posted by tamil13 <ta...@gmail.com>.
It is working now. Can we config below coding in camel-context.xml also? 

ProducerTemplate template;
template = context.createProducerTemplate();
Map<String, Object> map = new HashMap<String, Object>();
map.put("To", "davsclaus@apache.org");
map.put("From", "jstrachan@apache.org");
map.put("Subject", "Camel rocks");

String body = "Hello Claus.\nYes it does.\n\nRegards James.";
template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map); 

Thanks in advance.



--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725286.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

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

See for example
http://camel.apache.org/walk-through-an-example.html


On Tue, Jan 8, 2013 at 2:51 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Tue, Jan 8, 2013 at 2:48 PM, tamil13 <ta...@gmail.com> wrote:
>>
>> Yes. We included *real mail server* detail only. This is same code except
>> configuration information.
>> Below code return null pointer exception also.
>> Is there any other code available to create and send mail using *smtp*
>> component?
>>
>
> And did you create a template, eg
>
> template = camelContext.createProducerTemplate();
>
> So its not null.
>
>
>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725124.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel-mail

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 8, 2013 at 2:48 PM, tamil13 <ta...@gmail.com> wrote:
>
> Yes. We included *real mail server* detail only. This is same code except
> configuration information.
> Below code return null pointer exception also.
> Is there any other code available to create and send mail using *smtp*
> component?
>

And did you create a template, eg

template = camelContext.createProducerTemplate();

So its not null.



>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725124.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: camel-mail

Posted by tamil13 <ta...@gmail.com>.
Yes. We included *real mail server* detail only. This is same code except
configuration information.
Below code return null pointer exception also. 
Is there any other code available to create and send mail using *smtp*
component?




--
View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119p5725124.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-mail

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

Welcome to the community.

The code below is from an unit test, which uses a mock mail server
(not a real mail server).
In your scenario, you should change the details to a real mail server
(in case you want to send the emails for real).


On Tue, Jan 8, 2013 at 2:28 PM, tamil13 <ta...@gmail.com> wrote:
>
> Hi. I am new to camel. just finished studying 'camel in action' book. but
> There is no mail configuration information in it. Using camel, I want to
> send a mail using *smtp* component. I tried everything as much as possible.
> but There is no progress.
> All I need is I want to create a new message, setting properties,
> customizing message body and send it using camel smtp component.
>
> I tried following coding.
>
> ProducerTemplate template;
> Map<String, Object> map = new HashMap<String, Object>();
> map.put("To", "davsclaus@apache.org");
> map.put("From", "jstrachan@apache.org");
> map.put("Subject", "Camel rocks");
>
> String body = "Hello Claus.\nYes it does.\n\nRegards James.";
> template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
>
> I am getting null pointer exception in template.sendBodyAndHeaders() method.
> when I run above code.
>
>
> Thanks in advance...
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-tp5725119.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen