Embed HTML table in email

2020-06-12 06:00发布

Is it possible to send a table (coded in html) as the body of an email so that the recipient is able to view the table (parsed and displayed).

For example, I want to be able to send this as the body of an email:

<html>
    <table>
        <tr> 
            <td> col1 </td> 
            <td> col2 </td> 
        </tr> 
    </table> 
</html>

So that the recipient sees col1 col2.

I've read in some places that it's not possible and that I must use the table creator provided by the email service, but I'd just like to confirm to see if it's possible or not.

5条回答
老娘就宠你
2楼-- · 2020-06-12 06:42

You can not directly use HTML or Body tag when you embedding HTML in c# string as it already going to display inside HTML Page. Below is simple table format.

        body += "<table align ='center'>"

        body += "<tr>"
        body += "<td align = 'right' > Name :  </td>"
        body += "<td >" + Name + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Application ID :</td>"
        body += "<td  >" + ApplicationID + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Passport No :</td>"
        body += "<td >" + PassportNo + " </td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Voucher No. :</td>"
        body += "<td >" + VoucherNo + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Date :  </td>"
        body += "<td >" + PDate + "</td>"
        body += "</tr>"
        body += "</table><br>"

You can also do styling like below

Example

body+="<td style='padding:10px; height:20px; width=200px'>Hello World!</td>"
查看更多
家丑人穷心不美
3楼-- · 2020-06-12 06:45

You can create the table in HTML, open it up in a browser and copy & paste it into Outlook (based on the extra information you've provided in comments)

Outlook will make sense of your HTML, and provide in the same format as you pasted it.

If the client is using a text only e-mail (less likely nowadays - with most smartphones parsing HTML emails) then it will just appear a similar way to:

Header| Header 2 | Header 3
Test  | test     |  Test
Test  | test     |  Test
Test  | test     |  Test

Without any styling.

查看更多
男人必须洒脱
4楼-- · 2020-06-12 06:50

Some years ago I found that you can insert a table in the email body when using Thunderbird. Since then I have switched to mutt. So, out of curiosity, I created a table in html by using latex2html on a simple latex table. I then opened the mutt editor to create an email and copied and pasted the html code into the mutt editor and closed it to go to the mutt compose menu. Before sending the email, I used Ctrl-t to edit the content type and change it from "text/plain" to "text/html". Upon sending the email and opening it in gmail in a browser, the table appeared exactly as I would have wanted.

So, in summary, one can paste an html table into the mutt editor (vim, in my case) and just change the content type before sending it.

查看更多
Lonely孤独者°
5楼-- · 2020-06-12 06:53

This will depend on the recipient's email client. Some display in HTML, others only display plain text.

查看更多
爷、活的狠高调
6楼-- · 2020-06-12 06:54

You can send an email with a table inside it containing data. Just make sure you style it as a 'table containing data'. Use this as an example.

This is if you are building an email.

<html>
<table width="600" style="border:1px solid #333">
  <tr>
    <td align="center">head</td>
  </tr>
  <tr>
    <td align="center">
      body 
      <table align="center" width="300" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #ccc;">
        <tr>
          <td> data </td>
          <td> info </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</html>
查看更多
登录 后发表回答