在电子邮件中嵌入 HTML 表格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6115197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:45:30  来源:igfitidea点击:

Embed HTML table in email

htmlhtml-tableembedhtml-email

提问by MKMan

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

是否可以将表格(以 html 编码)作为电子邮件正文发送,以便收件人能够查看表格(解析和显示)。

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.

以便收件人看到col1 col2

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

我在某些地方读到这是不可能的,我必须使用电子邮件服务提供的表创建者,但我只想确认一下是否可能。

回答by breezy

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

您可以发送一封table内部包含数据的电子邮件。只要确保你的风格它作为“包含数据表”。以此为例。

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>

回答by Dan

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

这将取决于收件人的电子邮件客户端。有些以 HTML 格式显示,有些只显示纯文本。

回答by Ryan McDonough

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)

您可以在 HTML 中创建表格,在浏览器中打开它并将其复制并粘贴到 Outlook 中(基于您在评论中提供的额外信息)

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

Outlook 将理解您的 HTML,并以与您粘贴时相同的格式提供。

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:

如果客户端使用纯文本电子邮件(现在不太可能 - 大多数智能手机解析 HTML 电子邮件),那么它将以类似于以下方式出现:

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

Without any styling.

没有任何造型。

回答by Vijay Kumbhoje

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.

当您将 HTML 嵌入到 c# 字符串中时,您不能直接使用 HTML 或 Body 标记,因为它已经将显示在 HTML 页面中。下面是简单的表格格式。

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

回答by John Flood

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

几年前,我发现使用 Thunderbird 时可以在电子邮件正文中插入表格。从那以后我就改用mutt了。所以,出于好奇,我通过在一个简单的乳胶表上使用 latex2html 创建了一个 html 表。然后我打开 mutt 编辑器创建一封电子邮件并将 html 代码复制并粘贴到 mutt 编辑器中并关闭它以转到 mutt 撰写菜单。在发送电子邮件之前,我曾经Ctrl-t编辑过内容类型并将其从“text/plain”更改为“text/html”。发送电子邮件并在浏览器中在 gmail 中打开它后,该表格完全符合我的要求。

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.

因此,总而言之,您可以将一个 html 表粘贴到 mutt 编辑器(在我的例子中是 vim)中,然后在发送之前更改内容类型。