开发者

Embed HTML table in email

开发者 https://www.devze.com 2023-03-07 22:56 出处:网络
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).

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.


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>


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


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消