如何在电子邮件中添加表格 [英] How can I add a table inside an email

查看:95
本文介绍了如何在电子邮件中添加表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MailMessage msg = new MailMessage();
                msg.To.Add(new MailAddress(TextBox2.Text));
                MailAddress address = new MailAddress("testme@yahoo.com");
                msg.From = address;
                msg.Subject =  "Test";
                msg.Body = TextBox4.Text;

<big></big>
                StringBuilder bodyInfo = new StringBuilder();
                bodyInfo.Append("<table>");
                //StringBuilder myBuilder = new StringBuilder();

                bodyInfo.AppendLine("<br /><br />");
                bodyInfo.AppendLine(string.Format("Dear {0},<br /><br />", TextBox6.Text));
                bodyInfo.AppendLine();
                bodyInfo.AppendLine("Please review the following:<br /><br /><br />");
                bodyInfo.AppendLine("<strong>1. Test  Guide.</strong><br />");
                bodyInfo.AppendLine("This guide contains ...............<br /><br />");
                bodyInfo.AppendLine("<strong>2. XML GuideInvoice Implementation Guide.</strong><br />");
                bodyInfo.AppendLine("This guide contains................<br /><br />");
                bodyInfo.AppendLine("Please complete Part 1 of the attached form. <br /><br />");
                bodyInfo.AppendLine("Sincerely,<br />")

推荐答案

我为您提供了一个示例:您需要添加表内部HTML并在HTML标头中指定内容类型,因此您需要像这样发送数据包:
I made a sample for you: you need to add the table inner HTML and specify content type in the HTML header, so you need to send the data packet like this one:
From: ....
To: ....
Subject: table test
MIME-Version: 1.0
Content-type: text/html; charset=utf-8

<html>
	<head>
		<style type="text/css"><!--
			table, td, th { border: solid thin; }
			td, th { padding-left: 1em; padding-right:1em; }
			th { background-color:silver; }
		--></style>
	</head>
<body>
<table>
    <tr>
        <th>Some header</th>
        <th>Some other header</th>
    </tr>
    <tr>
        <td>Data 1</td>
        <td>Data 2</td>&
    lt;/tr>
</table>

</body>
</html>



当然,您应该指定一些真实的FromTo标头,添加一些所需的可选标头,等等.



Of course, you should specify some real From and To headers, add some optional headers you need, etc.


在发送邮件之前添加以下代码行:
Add the following line of code before you send the mail:
msg.IsBodyHtml = true;


将保留您的html格式...

使用以下表结构:


will keep your html format...

Use the following table structure:

<table>
    <tr>
        <th>TH1</th>
        <th>TH2</th>
        <th>TH3</th>
    </tr>
    <tr>
        <td>R1C1</td>
        <td>R1C2</td>
        <td>R1C3</td>
    </tr>
    <tr>
        <td>R2C1</td>
        <td>R2C2</td>
        <td>R2C3</td>
    </tr>
</table>


这篇关于如何在电子邮件中添加表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆