How to create a table in outlook mail body programmatically

16,710

Solution 1

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

Solution 2

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.

Share:
16,710
NewAutoUser
Author by

NewAutoUser

Updated on June 04, 2022

Comments

  • NewAutoUser
    NewAutoUser almost 2 years

    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.

  • Colin Chen
    Colin Chen about 14 years
    The solution above does not require Outlook 2007 which is a BIG plus. There are many ways to create a HTML table, but the code above is all you need to send it.
  • aswzen
    aswzen almost 7 years
    msg.IsBodyHTML = true; should be msg.IsBodyHtml = true;