How to create a table in outlook mail body programmatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liadmz
    New Member
    • Jul 2009
    • 32

    How to create a table in outlook mail body programmatically

    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:
    Code:
     
    private string SetEmailBody(bool _withTime)
    {
    
             string tmp;
    
    
                tmp = "<HTML>\n <Body> \n<br> \n <table border=\"1\" cellspacing=\"0\" cellpadding=\"1\" style=\"width:1200; border:0.5px solid black;\">";
    
    
                tmp = tmp + "<tr bgcolor=\"#999999\">\n";
    
    
                tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>ID</Font></div></td>\n";
    
    
                if (_withTime)
                {
    
                	tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>Date</Font></div></td>\n";
    
    
                	tmp = tmp + "<td align=center style=\"border:0.5px solid black;\"><div><Font Face='Arial' Size=2>Time</Font></div></td>\n";
    
    
                }
    
    
                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";
    
    
    
                tmp = tmp + "</tr>\n";
    
    
                
                return tmp;
    }

    the second which add to the table new row:
    Code:
    private string EmailBodyAddLine(string ID, string time, string date, string URL, bool _withTime)
    {
    
                string tmp = "<tr>\n";
    
                //ID
                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);
    
    		
                //Include time stemp
    	    if (_withTime)
    	    {
    		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);
    
    		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);
    	    }
    
    
    
                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);
    
    
    
                tmp = tmp + "</tr>\n\n";
    
    
                return tmp;
    }

    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
    Last edited by Niheel; May 31 '10, 04:19 PM. Reason: added code details to question
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    You can insert html in to email body( stringbuilder). I don't think it should be a problem.
    HTML email using Outlook
    Last edited by Niheel; May 31 '10, 04:20 PM. Reason: code posted

    Comment

    Working...