Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

[resolved] Sending query result by mail

Highlighted
Eight Stars

[resolved] Sending query result by mail

Hi all,
This is more of a designing question than related to the tool.
I have a SQL query whose output I need to write in a message and send it using the tSendMail component.
Anyone has done something similar or can tell me how I can design this job ?
One job design that comes to my mind is:
tMysqlInput---row1 (Main)--->tMap---sql_data (Main)--->tFileOutDelimited
But then I get stuck.
I don't understand how I can read the contents of this delimited file and write it into the mail body.
Can anyone help me please?

Accepted Solutions
Highlighted
Moderator

Re: [resolved] Sending query result by mail

Hi,
You can pass query result to Context value then send them by tsendmail.
Please have a look at my screenshots.
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.

View solution in original post


All Replies
Highlighted
Four Stars

Re: [resolved] Sending query result by mail

Use following
tMysqlInput---row1 (Main)--->tJavaRow-->OnSubJobOk-->tPop
in tJavaRow read every row and write formatted data in the form of html to context variable
Use that context variable inside the body of mail.
Check the post by largo-- he used html template for composing message
you will get some idea from this.
Thanks
Vaibhav
Highlighted
Eight Stars

Re: [resolved] Sending query result by mail

Thanks Vaibhav
Can you give me the URL of largo's post?
Highlighted
Moderator

Re: [resolved] Sending query result by mail

Hi,
You can pass query result to Context value then send them by tsendmail.
Please have a look at my screenshots.
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.

View solution in original post

Highlighted
Eight Stars

Re: [resolved] Sending query result by mail

Thanks xdshi!
That helped a lot.
But I want to format the text into HTML.
If I write the following in the tJavaRow component:
context.messageVariable = context.messageVariable+"<tr><td>"+row1.column1+"</td><td>"+row1.column2+"</td></tr>"

and in the tSendMail's Message field I write:
"<html><body><table>"+context.messageVariable+"</table></body></html>"

The text in the mail appears as
<html><body><table><tr><td>value1.1</td><td>value2.1</td></tr><tr><td>value1.2</td><td>value2.2</td></tr></table></body></html>
Is it possible to format the mail as a HTML content mail
Highlighted
Eight Stars

Re: [resolved] Sending query result by mail

I got how to change the content type from largouwalid's post.
Thanks again vaibhav and xdshi for all your help!!
Highlighted
One Star

Re: [resolved] Sending query result by mail

You can write the HTML in to text files, use the context variables to update the text file, then import the text file as a global variable (string) eventually calling the global variable into the body of your email.

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 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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog