Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good day all, I have a table on my default.aspx page but i want to send the table as a message to my email but it is sending but it is not showing as table

C#
// that is how it is showing on my email..just copied some..not all .
<center id="ContentPlaceHolder1_cent"> <table id="ContentPlaceHolder1_table4" border="1" cellspacing="0" width="100%" style=" font-size:small; color:#000000; collapse" bordercolor="#999999"> <tr> <td colspan="2" rowspan="4" style="border:0"> <a href="http://www.difameg.com/default.aspx"> <img id="ContentPlaceHolder1_Image1" src="../Images/Difameg.png" /></a> </td> <td colspan="3" align="center" style="border:0"> <h1>Contact Us On:</h1> </td> </tr> <tr> <td colspan="3" align="right" style="border:0; border-left-width:1"> Website: <a target="_blank" href="http://www.123.com">http://www.123.com</a> | Email: <a href="mailto:info@123.com">info@123.com</a></td> </tr> <tr> <td colspan="3" align="right" style="border:0"> Phone: +234-803-468-2529, +234-708-256-8755</td> </tr> <tr> 



what i am looking at is the the formatting should be done properly on my email instead scattering


C#
// See my email script below..

 StringWriter sw = new StringWriter();
           
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
           cent.RenderControl(htw);
            string body = sw.ToString();

            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(HttpUtility.HtmlEncode(TxtEmail.Text));
           msg.To.Add(new MailAddress(TxtEmail.Text));

         
           msg.Subject = "From: me " + "--> " +  HttpUtility.HtmlEncode(TxtSubject.Text);
            msg.Body = HttpUtility.HtmlEncode(body);
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.Normal;
            SmtpClient mSmtpClient = new SmtpClient();
           
            mSmtpClient.Send(mMailMessage);
            msg.Dispose();
            MyClass.MyAlert(this, "Successfully Sent", "1234");


thanks... Kindl assist me on it..
Posted

While debugging, check the value of string body. Take that value and create one HTML file.
Then run that file in some browser and check if it appearing correctly or not. That is how it is going to appear in mail too.

Note :- The CSS applied to controls should be inline, otherwise, it won't appear as you expect it to be.

So, check that HTML, you will get the idea.
 
Share this answer
 
You have to use commands like in the next example:
C#
StringWriter writer = new StringWriter();
HtmlTextWriter html = new HtmlTextWriter(writer);
//
html.RenderBeginTag(HtmlTextWriterTag.Pre);
  html.WriteBreak();
  html.WriteEncodedText("...");
  //...
html.RenderEndTag();
html.Flush();
//
msg.Body = writer.ToString();
 
Share this answer
 
v2

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