我正在C#中开发一些程序,该程序将使用Outlook 2007发送邮件。为此,我希望在邮件主体中创建一个表,并需要在其中显示所需的数据。谁能让我知道我们如何在邮件主体中以编程方式创建表格。

有帮助吗?

解决方案

只需在标准HTML表中输出数据即可。

然后将其作为HTML电子邮件而不是纯文本发送。这是C#中的快速而肮脏的例子:

MailMessage msg = new MailMessage("From@Email.com", "To@Email.com");
msg.IsBodyHTML = true;
msg.Subject = "Subject line here";
msg.Body = "html goes here";

SmtpClient mailClient = new SmtpClient("YourEmailServer");
mailClient.Send(msg);

其他提示

为了创建表,您可以使用HTML表标签。

<table><tr>....</tr></table>.

这是代码:

MailMessage msg = new MailMessage("From@Email.com", "To@Email.com");
msg.IsBodyHTML = true;
msg.Subject = "Subject line here";
msg.Body = "<table border=1><tr><td>one</td></tr><tr><td>two</td></tr>";

SmtpClient mailClient = new SmtpClient("YourEmailServer");
mailClient.Send(msg);

希望这对您有帮助。

尝试这个

using outlook = Microsoft.Office.Interop.Outlook;

string emailSubject = "Subject of email";   
string htmlString = "<table><tr><td>Hi</td></tr></table>";

outlook.Application outlookApp = new outlook.Application();
outlook.MailItem mailItem = (outlook.MailItem)outlookApp.CreateItem(outlook.OlItemType.olMailItem);
mailItem.Subject = emailSubject;
mailItem.HTMLBody = htmlString;
mailItem.To = "someaddress@someaddress.com";

mailItem.Save();

这将在您的Outlook>“ Drafts”文件夹中创建一个新消息,并带有单行表,上面写着“ HI”

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top