HTML电子邮件格式问题 [英] HTML e-mail message format problem

查看:91
本文介绍了HTML电子邮件格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一种将HTML格式的电子邮件发送给收件人的方法.我一直在尝试以适当的方式发送它,但是我得到的只是与正文格式相同的书面内容.它没有填充字段.代码是这样的:

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:

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 :

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?

推荐答案

您的编码有误.
您正在将格式化的文本分配给message.Body.
执行分配后,body变量仍包含未格式化的文本.但是稍后,您再次将未格式化的body变量分配给message.Body

如果您更换它,
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.


这篇关于HTML电子邮件格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆