在var html = string.Format中创建html电子邮件格式



大家好。

我正在ASP.NET中创建一个html电子邮件。现在的问题是,当我想添加任何东西到我的身体除了html和身体标签。当我想添加样式时,代码文件给了我错误,其中许多错误…

我想添加这个

<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8" />
        <title>Enquiry</title>
    </head>
    <body>
    <div style="margin: 0 auto; text-align: center; background: #3C3B3D; padding: 10px;">
        <h4 style="color: #F3911F">Website Enquiry</h4>
    </div>
    <table style="text-align: center; margin: 0 auto;">
        <tr>
            <td>name: </td>
            <td>{0}</td>
        </tr>
    </table>
    </body>
</html>

里面
var html = string.Format("THE HTML HERE", TextBoxName.Text)

当我将所有的html添加到字符串时,Visual studio基本上都加了下划线(上面所有的html)…

如何在ASP中设置邮件正文的格式/样式?

谢谢

必须转义所有引号字符。有两个选项:

// for single line texts use 
var x = "abcd"efg"hij";
// for multiple lines use @ and double quotes
var x = @"abcd
""efg""
hij";

当使用String.Format时,您还必须转义任何可能出现的{}字符(例如,在CSS或JavaScript块中,使用双{{}}

)
var x = string.Format("This is the value: {0} and this is just the brackets {{asd}}", 1);

可以使用stringbuilder . append ()

一个简单的邮件发送代码在这里

最新更新