在电子邮件中嵌入背景图像

发布于 2024-08-12 10:01:57 字数 951 浏览 3 评论 0原文

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

        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>

它没有t 显示,但是当我将它作为图像放入时,这样就可以了:

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

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

非常感谢提前:)

I'm trying to use an embedded image in an e-mail as the background image, i've got the following code to embed it:

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

Then in the e-mail body i've got the following code to test:

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

It doesn't display, but when i put it in as an image like this is is fine:

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

Does anyone one know why it won't display as a background?

Many thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

定格我的天空 2024-08-19 10:01:57

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

在使用您的电子邮件客户端进行测试之前请检查这一点:
http://www.campaignmonitor.com/css/

Do note that MS Outlook 2007, Live Hotmail etc do not support email content with background images of an sort, be it body, tables etc.

Check this before testing with your email client:
http://www.campaignmonitor.com/css/

梦醒时光 2024-08-19 10:01:57

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

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

Unfortunately you cannot reliably use background images in e-mails as many popular email clients do no render them.

I've spent many frustrating hours trying to work around this and as yet have not found a nice solution!

微暖i 2024-08-19 10:01:57

您尝试过以下操作吗?您可以在电子邮件中使用 CSS - 只需使用背景图像属性。

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

我只在 Apple Mail 中测试过此片段!

Did you try the following? You can use CSS in your E-Mails - just use the background-image property.

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

I have tested this snippet only in Apple Mail!

维持三分热 2024-08-19 10:01:57

使用这个

字符串 Body = "";

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 设置

Use this

string Body = "";

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);

After this you can use smtp settings

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文