By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,268 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,268 IT Pros & Developers. It's quick & easy.

How to create a table in outlook mail body programmatically

P: 32
I'm trying to create an email message which contains a table.
in the table I have one column that contains a URLs.

because I don't want the table to be too wide I want to limit the URL column,

I tried using nowarp tags in the table but with no luck.
I tried using CSS but it seems like the outlook is removing them.

my code is:

have two function that create the HTML code:

the first which creates the table headers:
Expand|Select|Wrap|Line Numbers
  1.  
  2. private string SetEmailBody(bool _withTime)
  3. {
  4.  
  5.          string tmp;
  6.  
  7.  
  8.             tmp = "<HTML>\n <Body> \n<br> \n <table border=\"1\" cellspacing=\"0\" cellpadding=\"1\" style=\"width:1200; border:0.5px solid black;\">";
  9.  
  10.  
  11.             tmp = tmp + "<tr bgcolor=\"#999999\">\n";
  12.  
  13.  
  14.             tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>ID</Font></div></td>\n";
  15.  
  16.  
  17.             if (_withTime)
  18.             {
  19.  
  20.                 tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>Date</Font></div></td>\n";
  21.  
  22.  
  23.                 tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>Time</Font></div></td>\n";
  24.  
  25.  
  26.             }
  27.  
  28.  
  29.             tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div style=\"width : 40px; word-break : break-all; overflow : hidden; text-overflow: hidden;\"><Font Face='Arial' Size=2>Link</Font></div></td>\n";
  30.  
  31.  
  32.  
  33.             tmp = tmp + "</tr>\n";
  34.  
  35.  
  36.  
  37.             return tmp;
  38. }
  39.  

the second which add to the table new row:
Expand|Select|Wrap|Line Numbers
  1. private string EmailBodyAddLine(string ID, string time, string date, string URL, bool _withTime)
  2. {
  3.  
  4.             string tmp = "<tr>\n";
  5.  
  6.             //ID
  7.             tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div id=\"idcol\"><Font Face='Arial' Size=2>%id%</Font></div></td>\n".Replace("%id%", ID);
  8.  
  9.  
  10.             //Include time stemp
  11.         if (_withTime)
  12.         {
  13.         tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div id=\"timecol\"><Font Face='Arial' Size=2>%date%</Font></div></td>\n".Replace("%date%", date);
  14.  
  15.         tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div id=\"timecol\"><Font Face='Arial' Size=2>%time%</Font></div></td>\n".Replace("%time%", time);
  16.         }
  17.  
  18.  
  19.  
  20.             tmp = tmp + "<td align=left style=\"border:0.5px solid black;\"><div style=\"height : 19px; width : 40px; word-break : break-all; overflow : hidden; text-overflow: hidden;\"><Font Face='Arial' Size=2>%URL%</Font></div></td>\n".Replace("%URL%", URL);
  21.  
  22.  
  23.  
  24.             tmp = tmp + "</tr>\n\n";
  25.  
  26.  
  27.             return tmp;
  28. }
  29.  

then I close the final string with
"</table>\n </html> "

and save it to the outlook draft

But when open in the outlook draft, seems like the CSS is partial working
for ex' the <div> size limit and the text over-flow are not implemented.

Thanks
May 30 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 750
PRR
You can insert html in to email body( stringbuilder). I don't think it should be a problem.
HTML email using Outlook
May 31 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.