How to set email addresses dynamically in cMail component in mediation route

Six Stars

How to set email addresses dynamically in cMail component in mediation route

Hi,

 

I noticed that we can set email properties such as Host,To, Subject, From.. 

Can we do it dynamically? I have these values in properties of exchange object.

Generally we can use exchange properties in many components of mediation but how to use them in cMail component?

 

Thanks in advance!

Tags (1)

Accepted Solutions
Six Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Hi Richard,

 

It worked with some play around. Basically talend cMail component does not provide the flexibility to set the values for the parameters available in it's setting (other than context variables).

But as you suggested it should work with headers, I added cSetHeader component before cMail component and it worked like charm. 

It looks like, in cMail if there is any header with which has the name same as the argument then header takes precedence over argument (option) in the uri.

 

Thanks once again!


All Replies
Sixteen Stars

Re: How to set email addresses dynamically in cMail component in mediation route

I believe you can do this using headers and the Apache Simple language (http://camel.apache.org/simple.html). Set your headers using either a cProcessor or cSetHeader and use the Simple Language to assign the values in the cmail.
Six Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Hi,

 

What I noticed is cMail component in talend is not allowing to access headers or properties of exchange.

When I put the context variables it works fine but when I try to put headers/properties, it does not recognize it.

Even there seems no option to use language. 

Sixteen Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Hmmmmm, I'm sure it should work..... but it can take some playing around to get it right. You shouldn't need to have the Single option, you should just need to format the String correctly. Unfortunately I can't try it here as I don't have my computer.

Something like....

"${in.header.headername}"

.....should do it.

Another (harder) way is to use PropertyPlaceholders. This is described below...
https://www.talendforge.org/forum/viewtopic.php?id=55428

Contexts will work, but you will not be able to change them at runtime.
Six Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Hi Richard,

 

It worked with some play around. Basically talend cMail component does not provide the flexibility to set the values for the parameters available in it's setting (other than context variables).

But as you suggested it should work with headers, I added cSetHeader component before cMail component and it worked like charm. 

It looks like, in cMail if there is any header with which has the name same as the argument then header takes precedence over argument (option) in the uri.

 

Thanks once again!

Sixteen Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Glad you got it working. Did you use the Simple Language syntax I gave you?
Six Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Not actually, I used 'Property' language to set the values in headers as I had the values available in exchange properties.

Five Stars

Re: How to set email addresses dynamically in cMail component in mediation route

Can you provide code put in cprocessor and syntax used in cmail ? I'm facing the exact same problem and can't achieve it.