在电子邮件正文中创建表 [英] create table in email body

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

问题描述

我正在创建一个窗口应用程序,我希望以表格格式发送数据。

I am making one window application in which I want to send data in table format.

推荐答案

我可以提问吗?您是否正在尝试开发UWP项目?或者你想要创建一个桌面项目?

May I have a question? Are you trying to develop a UWP project? Or you are tying to create a desktop project?

如果它是在UWP应用程序上,你可能需要使用来自  System.Net.Mail命名空间。使用  MailMessage类创建新邮件。然后你
可以使用HTML字符串创建一个表并启用MailMessage.IsBodyHtml属性为true。 

If it's on UWP apps, you might need to use the .net APIs from System.Net.Mail Namespace. Use MailMessage Class to create a new Mail message. Then you could use HTML string to create a table and enable the MailMessage.IsBodyHtml property to true. 

代码如下所示:

 string textBody = "<table border=" + 1 + " cellpadding=" + 0 + " cellspacing=" + 0 + " width = " + 400 + "><tr bgcolor='#4da6ff'><td><b>Inventory Item</b></td> <td> <b> Required Qunatity </b> </td></tr>";

            MailAddress addressFrom = new MailAddress(xxxx@xxx.com, "Roy");
            MailAddress addressTo = new MailAddress(xxxx@xxx.com);
            MailMessage message = new MailMessage(addressFrom, addressTo);

            message.Subject = "Sending Email with HTML Body";
            message.IsBodyHtml = true;
            message.Body = textBody;

            SmtpClient client = new SmtpClient();
            client.Host = "smtp-mail.outlook.com";
            client.Port = 587;
            client.Credentials = new System.Net.NetworkCredential("xxxx@xxx.com", "xxxx");
            client.EnableSsl = true;

            client.Send(message);

电子邮件如下所示:

祝你好运,

Roy


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

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