在电子邮件中嵌入 HTML 表格

发布于 2024-11-09 22:14:51 字数 407 浏览 7 评论 0原文

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

例如,我希望能够将其作为电子邮件正文发送:

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

以便收件人看到 col1 col2

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

饭团 2024-11-16 22:14:51

您可以发送一封电子邮件,其中包含一个包含数据的表格。只需确保将其样式设置为“包含数据的表格”即可。以此为例。

这是如果您正在构建电子邮件。

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

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>
装纯掩盖桑 2024-11-16 22:14:51

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

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

难理解 2024-11-16 22:14:51

c# 字符串中嵌入 HTML 时,不能直接使用 HTMLBody 标记,因为它已经显示在 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>"
       

一样进行样式设置

您还可以像下面的示例

body+="<td style='padding:10px; height:20px; width=200px'>Hello World!</td>"

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>"
我也只是我 2024-11-16 22:14:51

您可以用 HTML 创建表格,在浏览器中将其打开,然后复制并复制该表格。将其粘贴到 Outlook 中(根据您在评论中提供的额外信息)

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

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

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

没有任何样式。

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.

烟花肆意 2024-11-16 22:14:51

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文