Regarding guidance related to HTML table in email body

Hello All,

I have a query here. I am sending an HTML table(which I am creating it by a call to REST API, in a LINUX box) and from there I have to send it into an email. So following are the poins on same:

  1. As data is not static so it is writing Dynamic data and creating HTML file.
  2. There is a table which has many fields into it in that HTML file.
  3. I am sending this HTML table into an email by shell script(command sendmail ).
  4. All field's value could be of any length.

So above are some information points on this, following is the question now on same.

Query:
As I mentioned above field's length could be any. So when I am sending that email with HTML table, so it's one field has more length compare of any other field, so because of it all other fields(including columns and data) are shrinking into size and it is looking very odd in email. Basically I require all the fields to be same width and all values should come in single line into email, off course there could be a limit for wordwrap but field's data should go till that but that's not happening.

Following are the things I had tried too in order to fix it(which didn't work):

  1. Tried to fix table's width.
  2. Used {"white-space: nowrap"} .

Tried above but it didn't work, I can't paste data here apologies for it but I have tried my best to explain the issue, please do let me know if any further information required here too. Could anyone please help in same, will be grateful.

Thanks,
R. Singh

Try using table cell with nowrap attribute:-

<td nowrap>

By the way white-space is a CSS property, show us how you are using it.

Thanks Yoda for your reply, yes it is a css property but we could use it either with head and style tags or we could use it in td tag. I tried both but nothing worked. Sorry can't paste samples but it is very easy to predict like the last field/any filed is having long length data so all other fields are shrinking, which I don't want to be. Could you/form please guide me in same.

Thanks,
R. Singh

What email client is this being shown in? Microsoft ones restrict a lot of HTML features to avoid having to actually patch any security holes.

1 Like

Thank you for your reply Corona688, yes it is Microsoft Outlook client. Could you please guide me in same.

Thanks,
R. Singh

Please post sample data

Hello All,

I have solved my problem in this thread, sorry for late reply on this.
Following is my test data.

_____________________________________________________________________________________________
|TEST | TEST_1 | TEST_2_   | TEST_3 | TEST_4 | TEST_5_TES_TEST_TEST_TEST_TEST_TEST_TEST_TEST|
|     |        |AGAIN_TEST |        |        |                                              |
 _____________________________________________________________________________________________
 

Not sure if above gives clear picture of question or not. As we could see some column's data are not coming into a single line. So I wanted to have them in a single line. So in order to fix this in email(outlook client) I have increased the length of the problematic columns let's say column 6th I have changed from test_test_test to test_singh_test_singh_test so it has increased the width of the whole column in table. I had tried seveal options in it but it didn't work so in order to fix it I have done this non-technical fix. If anyone has any fix for this, it is always welcome.

Thanks,
R. Singh

I'm afraid I still don't understand the question. You want it to wrap lines? Why not insert newline characters or <br> breaks?

Hello Corona688,

Apologies for not being clear as I have copy and pasted HTML table in code tags but it was not shown as a table, finally ended up with writing a small awk to shown up following.

_____________________________________________________________________________________________
|TEST | TEST_1 | TEST_2_   | TEST_3 | TEST_4 | TEST_5_TES_TEST_TEST_TEST_TEST_TEST_TEST_TEST|
|     |        |AGAIN_TEST |        |        |                                              |
_____________________________________________________________________________________________

So as you could see 3rd column whose value is TEST_2_AGAIN_TEST was previously not coming on same line, in a single row. So I have done 2 things.

i- Have changed the largest column(last column here) values(because of which other columns were getting shrink) I have put it's values separated by space so in html it not increase it's(column's) width it will print then as follows to it.

 _____________________________________________________________________________________________
|TEST | TEST_1 | TEST_2_ AGAIN_TEST  | TEST_3 | TEST_4 | TEST|
|     |        |                     |        |        | 5   |
|     |        |                     |        |        |TEST |
                                                         .
                                                         .
                                                         .
                                                         so on to all values.
_____________________________________________________________________________________________

ii- Second thing I have done it I had increased the heading(means summary of shrink 3rd column) so by doing these 2 steps it is not shrinking the columns now.

Thanks,
R. Singh

So setting nowrap attribute should resolve this issue.

Here is an example:-

{
        print "From: from@domain.com"
        print "To: to@domain.com"
        print "MIME-Version: 1.0"
        print "Content-Type: text/html"
        print "Subject: Test Email"
        print "<html><body>"
        print "<html>"
        print "<body>"
        print "<table width=100% border=1 cellspacing=1 cellpadding=3>"
        print "<tr>"
        print "<td nowrap><font face=verdana size=1><b>COL 1</font></td>"
        print "<td nowrap><font face=verdana size=1><b>COL 2</font></td>"
        print "<td nowrap><font face=verdana size=1><b>COL 3</font></td>"
        print "<td nowrap><font face=verdana size=1><b>COL 4</font></td>"
        print "<td nowrap><font face=verdana size=1><b>COL 5</font></td>"
        print "<td nowrap><font face=verdana size=1><b>COL 6</font></td>"
        print "</tr>"
        print "<tr>"
        print "<td nowrap><font face=verdana size=1>TEST_1</font></td>"
        print "<td nowrap><font face=verdana size=1>TEST_2</font></td>"
        print "<td nowrap><font face=verdana size=1>TEST_3 AGAIN TEST_3 TEST_3 TEST_3 TEST_3 TEST_3 TEST_3 TEST_3</font></td>"
        print "<td nowrap><font face=verdana size=1>TEST_4</font></td>"
        print "<td nowrap><font face=verdana size=1>TEST_5 TEST_5 TEST_5TEST_5 TEST_5 TEST_5TEST_5 TEST_5 TEST_5TEST_5 TEST_5 TEST_5TEST_5 TEST_5 TEST_5</font></td>"
        print "<td nowrap><font face=verdana size=1>TEST_6</font></td>"
        print "</tr>"
        print "</table>"
        print "<body>"
        print "<html>"
} | /usr/sbin/sendmail -t

Here is the screenshot of email that I received, you can see that table cells were not wrapped even when I view email in restore down mode:-