Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed HTML table in email

Is it possible to send a table (coded in html) as the body of an email so that the recipient is able to view the table (parsed and displayed).

For example, I want to be able to send this as the body of an email:

<html>
    <table>
        <tr> 
            <td> col1 </td> 
            <td> col2 </td> 
        </tr> 
    </table> 
</html>

So that the recipient sees col1 col2.

I've read in some places that it's not possible and that I must use the table creator provided by the email service, but I'd just like to confirm to see if it's possible or not.

like image 562
MKMan Avatar asked May 24 '11 18:05

MKMan


2 Answers

This will depend on the recipient's email client. Some display in HTML, others only display plain text.

like image 114
Dan Avatar answered Nov 03 '22 02:11

Dan


You can not directly use HTML or Body tag when you embedding HTML in c# string as it already going to display inside HTML Page. Below is a simple table format.

        body += "<table align ='center'>"
        
        body += "<tr>"
        body += "<td align = 'right' > Name :  </td>"
        body += "<td >" + Name + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Application ID :</td>"
        body += "<td  >" + ApplicationID + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Passport No :</td>"
        body += "<td >" + PassportNo + " </td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Voucher No. :</td>"
        body += "<td >" + VoucherNo + "</td>"
        body += "</tr>"
        body += "<tr>"
        body += "<td align = 'right' > Date :  </td>"
        body += "<td >" + PDate + "</td>"
        body += "</tr>"
        body += "</table><br>"
       

You can also do styling like below

Example

body+="<td style='padding:10px; height:20px; width=200px'>Hello World!</td>"
like image 35
AirCode One Avatar answered Nov 03 '22 01:11

AirCode One