开发者

How to create a table in outlook mail body programmatically

开发者 https://www.devze.com 2022-12-25 13:12 出处:网络
I am developing some program in C# which will send the mail using outlook 2007. For this I wish 开发者_JAVA技巧to create a table in mail body and need to show the required data in it. Can anyone let m

I am developing some program in C# which will send the mail using outlook 2007. For this I wish 开发者_JAVA技巧to create a table in mail body and need to show the required data in it. Can anyone let me know how we can create a table programmatically in mail body.


Just output the data in a standard HTML table.

Then send it as an HTML email instead of plain text. Here's a quick and dirty example in 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);


For creating a table you can use HTML table tag.

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

Here is the code:

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

Hope this will be helpful for you.


Try this

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();

This will create a new message in your Outlook > Drafts folder with a single row table that says "Hi"

0

精彩评论

暂无评论...
验证码 换一张
取 消