c# - 表不继承 css 到控制台应用程序中的电子邮件 Html 模板

标签 c# html css console

我在控制台应用程序中有一个 Html 模板我必须使用这个模板发送邮件一切正常但是 css 没有应用在这个模板中我在同一个 html 页面上写了 css 我知道我可以使用表的属性,如 bgcolor 和表中的所有属性,但这不是解决方案......

我的html模板代码是

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Mail Alert For Tenders</title>
<style media="screen" type="text/css">
    .Table
    {
        margin: 1px 1px 1px 1px;
        width: 600px;
        -moz-border-radius-bottomleft: 3px;
        -webkit-border-bottom-left-radius: 3px;
        border-bottom-left-radius: 3px;
        -moz-border-radius-bottomright: 3px;
        -webkit-border-bottom-right-radius: 3px;
        border-bottom-right-radius: 3px;
        -moz-border-radius-topright: 3px;
        -webkit-border-top-right-radius: 3px;
        border-top-right-radius: 3px;
        -moz-border-radius-topleft: 3px;
        -webkit-border-top-left-radius: 3px;
        border-top-left-radius: 3px;
    }
    .Table table
    {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        border-collapse: collapse;
        border-spacing: 0;
    }
    .Table tr:last-child td:last-child
    {
        -moz-border-radius-bottomright: 3px;
        -webkit-border-bottom-right-radius: 3px;
        border-bottom-right-radius: 3px;
    }
    .Table table tr:first-child td:first-child
    {
        -moz-border-radius-topleft: 3px;
        -webkit-border-top-left-radius: 3px;
        border-top-left-radius: 3px;
    }
    .Table table tr:first-child td:last-child
    {
        -moz-border-radius-topright: 3px;
        -webkit-border-top-right-radius: 3px;
        border-top-right-radius: 3px;
    }
    .Table tr:last-child td:first-child
    {
        -moz-border-radius-bottomleft: 3px;
        -webkit-border-bottom-left-radius: 3px;
        border-bottom-left-radius: 3px;
    }

    .Table tr:nth-child(odd)
    {
        background: -o-linear-gradient(bottom, #4da28f 5%, #56998a 100%);
        background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, #4da28f), color-stop(1, #56998a) );
        background: -moz-linear-gradient( center top, #4da28f 5%, #56998a 100% );
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#4da28f", endColorstr="#56998a");
        background: -o-linear-gradient(top,#4da28f,#56998a);
        background-color: #4da28f; /*border:0 dashed #000000;*/
        text-align: justify;
        border-width: 0 0 1px 1px;
        font-family: Arial;
        font-weight: bold;
        color: #ffffff;
    }
    .Table tr:nth-child(even)
    {
        background: -o-linear-gradient(bottom, white 5%, #e5e5e5 100%);
        background: -webkit-gradient( linear, left top, left bottom, color-stop(0.05, white), color-stop(1, #e5e5e5) );
        background: -moz-linear-gradient( center top, #ff7f00 5%, white 100% );
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="white", endColorstr="#e5e5e5");
        background: -o-linear-gradient(top,white,FFFFCC);
        background-color: white;
        text-align: justify;
        border-width: 0 0 1px 1px;
        font-family: Arial;
        font-weight: bold;
        color: black;
    }
    .Table td
    {
        vertical-align: middle;
        border-width: 0 1px 1px 0;
        text-align: left;
        padding: 1em 3px 30px 5px;
        font-size: 12px;
        font-family: Arial;
        font-weight: 600;
    }
    .Table tr:last-child td
    {
        border-width: 0 1px 0 0;
    }
    .Table tr td:last-child
    {
        border-width: 0 0 1px 0;
    }
    .Table tr:last-child td:last-child
    {
        border-width: 0 0 0 0;
    }

    .Table tr:first-child td:first-child
    {
        border-width: 0 0 1px 0;
    }
    .Table tr:first-child td:last-child
    {
        border-width: 0 0 1px 1px;
    }
</style>
</head>
<body>

<div class="Table">
    <table>
        <tr>
            <td width="15%">
                Tender Title
            </td>
            <td colspan="3" width="85%">
                {TenderTitle}
            </td>
        </tr>
        <tr>
            <td width="15%">
                Tender ID
            </td>
            <td width="35%">
                {TenderID}
            </td>
            <td width="15%">
                Tender Type
            </td>
            <td width="35%">
                {TenderType}
            </td>
        </tr>
        <tr>
            <td width="15%">
                Tender Value
            </td>
            <td width="35%">
                {TenderValue}
            </td>
            <td width="15%">
                Tender EMD
            </td>
            <td width="35%">
                {TenderEMD}
            </td>
        </tr>
        <tr>
            <td width="15%">
                Location
            </td>
            <td width="35%">
                {Location}
            </td>
            <td width="15%">
                Organization Name
            </td>
            <td width="35%">
                {OrgName}
            </td>
        </tr>
        <tr>
            <td width="15%">
                Last Date
            </td>
            <td width="35%">
                {LastDateForSubmission}
            </td>
            <td width="15%">
                Category
            </td>
            <td width="35%">
                {SubProductCatName}
            </td>
        </tr>
    </table>
</div>

发送邮件我使用了这个代码

using (var sReader = new StreamReader(TemplatePath))
      {
       var htmlTemplate = sReader.ReadToEnd();
       htmlTemplate = htmlTemplate.Replace("{TenderTitle}", tender.TenderTitle);
       htmlTemplate = htmlTemplate.Replace("{TenderID}", tender.TenderID.ToString("N1"));
       htmlTemplate = htmlTemplate.Replace("{TenderType}", tender.TenderTypeName);
       htmlTemplate = htmlTemplate.Replace("{TenderValue}", tender.TenderValue.ToString("Rs. ##,###"));
       htmlTemplate = htmlTemplate.Replace("{TenderEMD}", tender.TenderEMD);
                                    htmlTemplate = htmlTemplate.Replace("{Location}", tender.Location);
       htmlTemplate = htmlTemplate.Replace("{OrgName}", tender.OrgName);
                                    htmlTemplate = htmlTemplate.Replace("{LastDateForSubmission}", tender.LastDateForSubmission.ToString("yyyy mmmm dd"));
       htmlTemplate = htmlTemplate.Replace("{SubProductCatName}", tender.SubProductCatName);
       mailContent = htmlTemplate;
                                } 

通过此代码发送的邮件没有任何格式,意味着没有应用任何 css

最佳答案

<style> ... </style>属于 <head></head> , 不在 <body>标签

关于c# - 表不继承 css 到控制台应用程序中的电子邮件 Html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20281722/

相关文章:

css - chrome 中的透明主题颜色

css - WordPress 悬停下拉菜单

css - 如何在 CSS 中引用给定选择器的第一次出现?

c# - 在 App.config 中设置 WCF ClientCredentials

c# - C# 十进制类型除法的精度在 Mono 上不同吗?

html - 自定义定位图像在不同屏幕尺寸上的变化 - HTML/CSS

javascript - AngularJS 从数据库获取响应后如何加载 HTML 页面?

c# - 将 <text> 转换为字符串?

c# - 在 C# 中更新列表

CSS 对齐 - <h3> <span>