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)
1 ACCEPTED SOLUTION

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!

6 REPLIES
Fifteen 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.
Rilhia Solutions
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. 

Fifteen 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.
Rilhia 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!

Fifteen 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?
Rilhia Solutions
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.