c#中的通讯

时间:2011-05-23 17:17:35

标签: c# html

我正在使用c#发送邮件。在我的邮件中,我使用三个图像一个用于背景,一个用于headerimage,最后用于页脚图像。 但问题是,当我收到邮件时,我没有得到背景图片.. 我的图像代码是:

  imgAtt.ContentId = "Winter.jpg";
ingatt1.ContentId = "images5.jpg";

                    MailMessage mail = new MailMessage();
                    mail.To.Add(to);
                    mail.From = new MailAddress(from);
                    mail.Subject = "In line image test";
                    mail.Body = "<html><body>" +
                    "<div style=\"width:300px; height:300px;border:4px solid; background-image:'cid:"+ingatt.ContentId+"\"> " +                 
                    "<center>" +
                    "<img style=\"width:100px; height:100px;\" src=\'cid:" + imgAtt.ContentId + "' /> " +
                    "</center>" +
                    "</div> " +
                    "</body>" +
                    "</html>";
                    mail.IsBodyHtml = true;
请某人帮帮我..

2 个答案:

答案 0 :(得分:2)

用这个

ingatt1.ContentId = "images5.jpg

"<div style=\"width:300px; height:300px;border:4px solid; background-image:'cid:"+ingAtt.ContentId+"\"> " +

应该是这个

"<div style=\"width:300px; height:300px;border:4px solid; background-image:'cid:"+ingatt1.ContentId+"\"> " +

答案 1 :(得分:0)

尝试

"<div style=\"width:300px; height:300px;border:4px solid; background-image: url('cid:"+ingatt.ContentId+"')\"> " +

这应该会导致background-image css规则的正确格式(http://www.w3schools.com/css/pr_background-image.asp