Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello,

I have a method that sends email in a HTML format to the recipient. I have been trying to send it in a proper way but all I get is the same written things which I wrote on the body format. It doesn't fill the fields. The code is like that:
C#
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                message.IsBodyHtml = true;
                string body = "<html><body>";

                body += @"<table border='1' cellspacing='0' cellpadding='0'>
                          <tr>
                            <td width='160' height='160'><a href='{0}'><img src='{1}' width='160' height='160' border='0px' /></a></td>
                            <td style='padding-left:10px'><table width='432' border='0' cellspacing='0' cellpadding='0'>
                              <tr>
                                <td><a style='font-size:18px; font-weight:bold'>ASIN: {2}</a></td>
                              </tr>
                              <tr>
                                <td><a style='color:#000; font-size:18px; font-weight:bold' href='{0}'>link</a></td>
                              </tr>
                              <tr>
                                <td>Review average has been changed from {3} to {4}.</td>
                              </tr>
                              <tr>
                                <td>Total review has been changed from {5} to {6}.</td>
                              </tr>
                              <tr>
                                <td>Price: {7}</td>
                              </tr>
                              <tr>
                                <td>Marketplace: {8}</td>
                              </tr>
                              <tr>
                                <td height='21'>Manufacturer: {9}</td>
                              </tr>
                            </table></td>
                          </tr>
                        </table>";

                message.Body = String.Format(body, detailpageurl, imageurl, asin,  String.Format("{0:0.#}", old_rating),  String.Format("{0:0.#}", rating), oldtotalreview, total_review, price, mercname, manufacturer);
                body += "</body></html>";
                message.Body = body;
                message.Subject = "Product Review";

And the email that I have received is :

XML
ASIN: {2}
link

Review average has been changed from {3} to {4}.
Total review has been changed from {5} to {6}.
Price: {7}
Marketplace: {8}
Manufacturer: {9}


can someone help me find the problem?
Posted
Updated 11-Dec-10 2:52am
v2
Comments
Sandeep Mewara 11-Dec-10 3:46am    
So you mean to say it is not getting formatted into HTML format?

1 solution

There is an error in your coding.
You are assigning the formatted text to message.Body.
After the assignment is executed the body variable still contains the unformatted text. But later on you are again assigning the unformatted body variable to the message.Body

If you replace this,
message.Body = String.Format(body, detailpageurl, imageurl, asin, String.Format("{0:0.#}", old_rating), String.Format("{0:0.#}", rating), oldtotalreview, total_review, price, mercname, manufacturer); 


with this,
body = String.Format(body, detailpageurl, imageurl, asin, String.Format("{0:0.#}", old_rating), String.Format("{0:0.#}", rating), oldtotalreview, total_review, price, mercname, manufacturer); 

It should work fine.
 
Share this answer
 
Comments
Rajitha Wimalasooriya 19-Dec-10 2:01am    
Why was the answer down voted? Is the given fix incorrect?

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