【问题标题】:Embedding background images in an e-mail在电子邮件中嵌入背景图像
【发布时间】:2010-12-18 17:44:09
【问题描述】:

我正在尝试使用电子邮件中的嵌入图像作为背景图像,我有以下代码可以嵌入它:

        LinkedResource backgroundLink = new LinkedResource("..\\..\\background.gif");
        backgroundLink.ContentId = "BackgroundImage";
        backgroundLink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
        htmlView.LinkedResources.Add(backgroundLink);
        m.AlternateViews.Add(htmlView);

然后在电子邮件正文中,我有以下代码要测试:

        <table background='cid:BackgroundImage'>
            <tr>
               <td>
                  test
               </td>
            </tr>
        </table>

它不显示,但是当我将它作为这样的图像放入时很好:

         <table>
            <tr>
               <td>
                  <img src='cid:BackgroundImage' />
               </td>
            </tr>
        </table>

有谁知道为什么它不会显示为背景?

提前非常感谢:)

【问题讨论】:

    标签: c# image background embedded-resource mailmessage


    【解决方案1】:

    您是否尝试过以下操作?您可以在电子邮件中使用 CSS - 只需使用 background-image 属性。

    <table style='background-image:url(cid:BackgroundImage)'>
                <tr>
                   <td>
                      test
                   </td>
                </tr>
            </table>
    

    我只在 Apple Mail 中测试过这个 sn-p!

    【讨论】:

      【解决方案2】:

      请注意,MS Outlook 2007、Live Hotmail 等不支持带有某种背景图像的电子邮件内容,无论是正文、表格等。

      在使用您的电子邮件客户端进行测试之前,请检查以下内容: http://www.campaignmonitor.com/css/

      【讨论】:

        【解决方案3】:

        不幸的是,您无法在电子邮件中可靠地使用背景图像,因为许多流行的电子邮件客户端不会呈现它们。

        我花了很多令人沮丧的时间试图解决这个问题,但还没有找到一个好的解决方案!

        【讨论】:

        • 这里也一样!确实令人沮丧。
        【解决方案4】:

        使用这个

        字符串正文 = "";

        AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

            LinkedResource imagelink = new LinkedResource(Server.MapPath("~/images/gmail_top.jpg"));
        
            LinkedResource imagelink1 = new LinkedResource(Server.MapPath("~/images/gmail_btm.jpg"));
            imagelink.ContentId = "imageId";
            imagelink1.ContentId = "imageId1";
            imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlView.LinkedResources.Add(imagelink);
        
            imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlView.LinkedResources.Add(imagelink1);
        

        Mail.AlternateViews.Add(htmlView);

        在此之后您可以使用 smtp 设置

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-05-16
          • 2012-07-23
          • 2014-03-28
          • 2011-10-06
          • 2015-01-29
          • 2014-10-03
          相关资源
          最近更新 更多