Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a table in outlook mail body programmatically

I am developing some program in C# which will send the mail using outlook 2007. For this I wish 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.

like image 213
NewAutoUser Avatar asked Feb 03 '26 18:02

NewAutoUser


2 Answers

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("[email protected]", "[email protected]");
msg.IsBodyHTML = true;
msg.Subject = "Subject line here";
msg.Body = "html goes here";

SmtpClient mailClient = new SmtpClient("YourEmailServer");
mailClient.Send(msg);
like image 75
Neil N Avatar answered Feb 06 '26 07:02

Neil N


For creating a table you can use HTML table tag.

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

Here is the code:

MailMessage msg = new MailMessage("[email protected]", "[email protected]");
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.

like image 36
Tausif Meman Avatar answered Feb 06 '26 09:02

Tausif Meman