0

What I want to do is;

for (int i = 0; i < thexfiles.Length; i++)
{
    tosend = tosend + "<tr><td>"+thexfiles[i]+"</td><td>"+thexdates[i]+"</td></tr><tr>";
}
mail.Body = tosend;

I want to insert the data into a table in a C# code (using html perhaps?), so when it's mailed it looks clean.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
paxcow
  • 1,670
  • 3
  • 17
  • 32

3 Answers3

2

Try this

    StringBuilder sb = new StringBuilder();
    sb.Append("<table>");
    sb.Append("<tr><td>Column 1</td><td>Column 2</td></tr>");

    for (int i = 0; i < thexfiles.Length; i++)
        sb.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", thexfiles[i], thexdates[i]);

    sb.Append("</table>");

    mail.IsBodyHtml = true;
    mail.Body = sb.ToString();
JohnnBlade
  • 4,261
  • 1
  • 21
  • 22
2

if you are using the class: System.Net.Mail.MailMessage make sure after assigning the content to the Body property you also set the property IsBodyHtml to true .

that should work.

Danish Khan
  • 1,893
  • 5
  • 22
  • 35
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
1

You simply have to do this:

for (int i = 0; i < thexfiles.Length; i++)
{
    tosend = tosend + "<tr><td>"+thexfiles[i]+"</td><td>"+thexdates[i]+"</td></tr>";
}

tosend = "<html><table>" + tosend + "</table></html>";

mail.IsBodyHtml = true;
mail.Body = tosend;

And that's it, the mail body will be shown in HTML table.

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105