Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I need to draw table structure in email message,like 4 columns and 4 rows.And need to work in all email client also,bcz i try in outlook vertical line not appear.need black borders.

I am give td background black and .Here i paste my table structure code

VB
Dim sb As New StringBuilder
         Dim sb As New StringBuilder
        sb.Append("<table cellpadding='0' cellspacing='0' style='width: 100%; font-family: Segoe UI, Tahoma, Verdana; font-size: 12px;'>")
        sb.Append("<tr><td colspan='9' style='font-weight: bold; font-size: 14px; padding-removed 10px; text-align: center;'>Alert</td></tr>")
        sb.Append("<tr><td colspan='9' height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td style='text-align: center'>File</td><td height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td style='text-align: center'>Alert </td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td style='text-align: center'>Search</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td style='text-align: center'>User Name</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td colspan='9' height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")

        sb.Append("<tr><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='left'>dfvgdvfdvf</td><td height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfvsfv s</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvgfdzvfdzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td colspan='9' height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='left'>dfvgdvfdvf</td><td height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfvsfv s</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvgfdzvfdzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td colspan='9' height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='left'>dfvgdvfdvf</td><td height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfvsfv s</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvdfzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td><td align='center'>fdvgfdzvfdzv</td><td width='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("<tr><td colspan='9' height='1px' style='background-repeat: no-repeat; background-color: #000000;'></td></tr>")
        sb.Append("</table>")


        Dim Smtp_Server1 As New SmtpClient
        Dim e_mail1 As New MailMessage()

        Smtp_Server1.UseDefaultCredentials = True
        Smtp_Server1.Credentials = New System.Net.NetworkCredential(xxxxx@gmail.com, xxxxx)
        Smtp_Server1.Port = 587
        Smtp_Server1.EnableSsl = True
        Smtp_Server1.Host = "smtp.gmail.com"

        e_mail1 = New MailMessage()
        e_mail1.From = New MailAddress(xxxxx@gmail.com)
        e_mail1.To.Add("xxxxx@gmail.com")
        e_mail1.Subject = "Test Mail"
        e_mail1.IsBodyHtml = True
        e_mail1.Body = sb.ToString
        Smtp_Server1.Send(e_mail1)


when see in mail in gmail,it ok but if open in outlook vertical line not appear.

Pls add in visual studio and send mail then only can see table structure in email.

Regards
Aravind
Posted
Updated 21-Sep-14 16:02pm
v6
Comments
hypermellow 19-Sep-14 5:07am    
Hi, can you post your code please?
Sergey Alexandrovich Kryukov 19-Sep-14 16:39pm    
OP did it; please see. The problem is not reproduced, but the quality of the code is pretty low. Please see my suggestions in Solution 1.
—SA
[no name] 19-Sep-14 5:33am    
send your html data in a string through mail
Aravindba 20-Sep-14 5:43am    
This message open in gmail http://prntscr.com/4oj76l and this is same message open in outlook(email client) http://prntscr.com/4oj7d6,u can see the different.

1 solution

First of all, I tried your HTML and see everything on white background, but in the Web browser. Perhaps your observations a wrong and what you see is the artifact of some defected mail viewer; I don't know what are you using to view it.

But your HTML code is bad and your table looks ugly. You are doing it wrong. Try to use better techniques:
  • In your mail content, write complete HTML document, starting from the
    <html><head></head><body> … </body></html>
    structure.
  • The above item will allow you to add CSS style sheet in the <head> element. Do it. If you need to learn CSS, do it.
  • Move all your style-related formatting from table to CSS. If you need different classes for different table elements, introduce them.
  • Even though your approach to composing strings using StringBuilder is correct, avoid doing it for such ad-hoc purposes. Instead, create some template string representing whole HTML (or say, whole HTML and, separately, a single row line) and insert actual data using string.Format. In other words, abstract out table data from table markup. The concrete solution depends on what do you want to achieve, what is your data schema and data abstraction.


—SA
 
Share this answer
 
Comments
Aravindba 20-Sep-14 5:43am    
Hi Thank u for ur reply,u know always raw code look ugly,even though ur code also look ugly,if u see output then only u see beautiful on it,above i mention at last line,if u use this code in visual studio then only understand anyway here i attach screen shot,this message open in gmail http://prntscr.com/4oj76l and this is same message open in outlook(email client) http://prntscr.com/4oj7d6,u can see the different.

Note:This html table structure used in windows application,i mean in service i will create and send email to admin on each day.

Sergey Alexandrovich Kryukov 20-Sep-14 11:35am    
Yes, that was my guess that this structure comes from some application, that's why I think you can properly format the table using some formats and data source, not hard-code it. You need to create format/style reasonably presentable in different mail viewer, by using simple and consistent style.
Will you accept this answer formally?
—SA
Aravindba 21-Sep-14 22:19pm    
Can u tell me ,what style need to add ? and how work for all email client ,bcz above i mention outlook client not work table structre.
Sergey Alexandrovich Kryukov 21-Sep-14 23:17pm    
I cannot, because I don't know your intentions.

But I can tell you what style properties you certainly need to use, for td, tr and td elements:
padding, margin, width (important: can use % units), text-align and border. Important: can use em units (font units, number of characters in padding-margin). And also perhaps font.
That's all for layout. On top of it, you can use colors and other things not affecting layout.
Also, you may need to control line breaks with the property white-space: nowrap.
For main principles, learn "box model":
http://www.w3.org/TR/CSS2/box.html,
http://www.w3.org/TR/css3-flexbox.

I hope I covered all the essential properties.

It's important not to use any ad-hoc style-related attributes except perhaps "class". But if you only have one table style, you can avoid most of them targeting styles to td, tr and th. But you often need separate styles for different td cells, typically leftmost, rightmost, and others — they often have different alignment or width.

—SA
Aravindba 22-Sep-14 0:08am    
Hi Thank u for ur reply,Actually css and styles are addition one,may be need to show table structure in attract one,but my need to i need only black borders,like http://prntscr.com/4oj76l ,in this table i will bind values dynamically,for understan i will hardcoded some values inside cells,top row only Statice others are dynamically bind vaules.in outlook not show verticall lines http://prntscr.com/4oj7d6.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900