How to design or manipulate HTML for send email

Dears,
I have workflow whcih has runing and in the last step emailed. but the output like this:

image

How can I change html tags or design the tags and table for body of this mail?
In addition I want to add the specefic xlsx file which has generate by this flow as a attchamnet of mail automatically.

Hi @natanzi,

To feed the Send Email node with HTML you need to use the Table to HTML String to convert the table to html. To attach the Excel file, write the Excel file and pass the file path to the Send Email node.

Then configure the node with these flow variables and execute.

Here is an example workflow:

send_email

send_mail.knwf (33.6 KB)

Feel free to ask any questions.

:blush:

3 Likes

Hi Armin,
Thank you for your response. The point is that the mail which has recived is not well design, So I want to modify the html tags before send. is there any idea?

The Table to HTML String node converts a table to HTML very well. I have tested the output:

email

If you want to manipulate the html further, you can use the String Manipulation node (or the variable variant) afterwards or you can export the table as an HTML file with the Table to HTML node and modify it externally then read the file with the File Reader node, concatenate the rows with the GroupBy node (with no delimiter) and convert it to a flow variable and pass it to the Send Email node.

:blush:

1 Like

I suspect the rendering of the table is more down to the mail client you use and how it chooses to render unstyled tables.

You could maybe look at doing some XML manipulation to add some inline styling to the HTML table that is generated.

If you could give an idea of what you want the table to look like if I find some time I can look at adding some pre-defined styles or custom styling options to the node.

I assume you are talking about things like border, background etc rather than number formatting?

Cheers

Sam

1 Like

It would appear there’s a compromise to be made to get custom styling.

KNIME render with custom styles:

Outlook render of the same HTML:

image

So the solution I’ve got for you is this:

A new tick box in the Table To HTML String node which allows the addition of this basic styling. It’s false by default so at to be backwards compatible.

This will now generate an HTML string that looks like this:

<html>
<body>
	<table border style="border:1px solid black; border-collapse: collapse">
		<tr style="background-color: black; color: white; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px">
			<th> <b> RowID </b> </th>
			<th> <b> column1 </b> </th>
			<th> <b> column2 </b> </th>
			<th> <b> column3 </b> </th>
		</tr>
		<tr style="padding: 0px;">
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;"> <b>Row0</b> </td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">1</td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">1.00</td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">A</td>
		</tr>
		<tr style="padding: 0px;">
			<td style="border: 1px solid #ddd;"> <b>Row1</b> </td>
			<td style="border: 1px solid #ddd;">2</td>
			<td style="border: 1px solid #ddd;">2.00</td>
			<td style="border: 1px solid #ddd;">B</td>
		</tr>
		<tr style="padding: 0px;">
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;"> <b>Row2</b> </td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">3</td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">30.54</td>
			<td style="border: 1px solid #ddd;background-color: #f2f2f2;">C</td>
		</tr>
		<tr style="padding: 0px;">
			<td style="border: 1px solid #ddd;"> <b>Row3</b> </td>
			<td style="border: 1px solid #ddd;">4</td>
			<td style="border: 1px solid #ddd;color: red;"> <b>?</b> </td>
			<td style="border: 1px solid #ddd;">D</td>
		</tr>
	</table>
</body>

I’ll try push this through to the nightly build shortly and update my comment when it’s available.

Cheers

Sam

3 Likes

Having some trouble getting a test that works locally to pass on the build server so the update won’t be available for a little while.

Cheers

Sam

Hi @swebb,

That would be a nice update. I like it. :+1:

:blush:

@natanzi the updated node is now available from the nightly build:

KNIME Community Contributions (trunk) - https://update.knime.com/community-contributions/trunk/

Should work from 3.7 onwards, probably 3.5 onwards but not tested.

Let me know how you get on.

Cheers

Sam

3 Likes

Dear @armingrudd ,
Thak you for your response.

Dear Sam, @swebb,
It would be grate solution to modify the HTML tags in table to HTML string node.
as I mentioned in my post, to modify the html/border/color in body of email, we need to have access to HTML.
I used last version of knime and update the library which you mentioned above, Im going to check the result…:grinning:

Dear Sam, @swebb,
I have test and result is fine. is it possible to get access to html tags by another tab in the mentioned node? I think it lets us to have more felexibility in our E-mails.

BR,
Milad

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.