[resolved] Problem with tSendMail and extern variables in properties file

Highlighted
One Star

[resolved] Problem with tSendMail and extern variables in properties file

Hi,
I try to use the component tSendMail with variables from an external file, but nothing goes right...
So I have
tFileInputProperties_1 ====Main====>tSetGlobalVar_1
   ||OnSubJobOk
   ||
tSendMail


In tFileInputProperties_1 :
File format : .properties
file Name: "./emailDetails.properties"



In tSetGlobalVar_1
Key : "row1.key"
Value : "row1.value"



In tSendMail
To : ((String)globalMap.get("To"))
From : ((String)globalMap.get("From"))

I have also try that:
To : ((String)globalMap.get("row2.value"))
From : ((String)globalMap.get("row1.value"))



In emailDetail.properties
From = abc@abc.com
To= sos@sos.net
host=smtp.gmail.com
port= 465
...


What's o the correct method?
Thank's
Burnside.


Accepted Solutions
One Star

Re: [resolved] Problem with tSendMail and extern variables in properties file

Hi,

I have solved my problem with this method.

tFileInputExcel_1 ---Main--- tFlowToIterate_1 ---Iterate--- tFixedFlowInput_1 --- Iterate --- TSendMail_1
tFileInputExcel_1 : The xls file with the values
tFlowToIterate_1 : Key="Mail" and value=Mail
tFixedFlowInput_1 : mode= Use Single Table
                             values=
                             |_>Column =>Mail
                             |_>values =>((String)globalMap.get("Mail"))
TSendMail_2 : Field to : ((String)globalMap.get("Mail"))


I join a print screen of the dashboard.


Hope It help you.
                 

View solution in original post


All Replies
Four Stars

Re: [resolved] Problem with tSendMail and extern variables in properties file

It looks like because you're using global variables, you're not passing the right key/value to the right global variable. Looks like you might have to do so conditionally (if key = "To" then load to variable "To" etc...). I suspect that if you were to print out the values of your global variables, you'd find that only the last set in your properties file stuck. It's always good practice to print out the values of your variables (System.out.println("key: " + ((String)globalMap.get("To")) )...


An alternative to using global variables would be to use context variables. Context variables are global variables whose values can be set outside the Talend job - from a file, like you're doing. Because the key/value pairs in the file map to key/value pairs in the job, it makes loading the values very easy. And, there's a component for doing so. As shown below, create context variables in your job, read the values from the file, connect them to a tContextLoad, select options to print the values - so you can confirm that your job is using the right values. 


One Star

Re: [resolved] Problem with tSendMail and extern variables in properties file

HI,
Thank's for your answer, but I'm new and I don't know yet everything...and english is not my mother language.
Is it possible to have an example from an xls file?
Ot just to have a vue from the dashboard?
regards
Burnside.
Moderator

Re: [resolved] Problem with tSendMail and extern variables in properties file

Hi Burnside,

Please take a look at a related forum:
https://community.talend.com/t5/Design-and-Development/resolved-need-to-send-the-data-of-tLogRow-to-tSendMail/m-p/70061

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] Problem with tSendMail and extern variables in properties file

Hi,

I have solved my problem with this method.

tFileInputExcel_1 ---Main--- tFlowToIterate_1 ---Iterate--- tFixedFlowInput_1 --- Iterate --- TSendMail_1
tFileInputExcel_1 : The xls file with the values
tFlowToIterate_1 : Key="Mail" and value=Mail
tFixedFlowInput_1 : mode= Use Single Table
                             values=
                             |_>Column =>Mail
                             |_>values =>((String)globalMap.get("Mail"))
TSendMail_2 : Field to : ((String)globalMap.get("Mail"))


I join a print screen of the dashboard.


Hope It help you.
                 

View solution in original post

Moderator

Re: [resolved] Problem with tSendMail and extern variables in properties file

Hi Burnside,

Thanks for your feedback and sharing your solution with us.

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog