c# - CSS 中的 LinkedResource

标签 c# css email smtp embedded-resource

我正在尝试发送带有 HTML 正文的电子邮件。 我在本网站和其他地方找到了许多示例,这些示例很好地解释了如何使用 LinkedResource IMG 类型的 HTML 标签的类。

在我的例子中,我有以下代码:

<table id="page" style="border: 2px solid #ff0000; ">
    <tr>
        [...]
    </tr>
</table>

和以下样式表:

    #page {
        width: 100%;
        height: 100%;
        top: 0;
        right: 0;
        background: url(https://www.example.com/img/bg.jpg) no-repeat center center;
        position: fixed;
        z-index: -1;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }

代码如下:

MailMessage mail = new MailMessage();
AlternateView plainView = AlternateView.CreateAlternateViewFromString( plainTextMessage, Encoding.UTF8, "text/plain" );
mail.AlternateViews.Add( plainView );
AlternateView htmlView = AlternateView.CreateAlternateViewFromString( htmlTextMessage, Encoding.UTF8, "text/html" );
mail.AlternateViews.Add( htmlView ); 
mail.Body = htmlTextMessage;  
mail.IsBodyHtml = true;
mail.To.Add( new MailAddress( customer.Email, customer.FullName ) );
mail.From = new MailAddress( "noreply@example.com", "My Web site" );

SmtpClient client = new SmtpClient();
client.Send( mail );

如何使用 LinkedResource 类嵌入背景图片?

最佳答案

您发布的代码将显示背景图片,具体取决于正在查看电子邮件的电子邮件客户端。 Outlook 2007-2010 不会,Gmail 或 Yahoo 也不会。 Apple 设备会。

对您的问题的评论建议将内容移动到内联,这将有助于增加客户数量。虽然,为了满足您的问题,我不确定 LinkedResource 是否可以用于此目的,但您可能想尝试使用 Bulletproof Backgrounds:https://backgrounds.cm

这将生成确保它适用于大多数电子邮件客户端所需的 HTML 代码。

关于c# - CSS 中的 LinkedResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34498777/

相关文章:

javascript - 如何使用 HTML、CSS 和 JavaScript 根据值更改行的背景颜色?

html - CSS - 如何设置一个巨大的图像到浏览器窗口的大小?

css - 使用 ng-show 和 ng-animate 向上/向下滑动效果

email - Jenkins 可以发送带有附件的邮件通知吗?

c# - 不使用 Visual Studio 创建 Wix Bootstrapper

c# - 如何跟踪我在其他网站上作为链接提供的软件

javascript - 如何在 Node js 中循环异步发送批量邮件?

javascript - 发送包含从 ajax 请求检索到的数据的电子邮件

c# - 重构:结合两种方法

c# - C# 中的 BitArrays 有问题吗?