美好的一天。
我在ASP.NET中创建一个html电子邮件。现在的问题是当我想向我的身体添加任何东西,除了html和body标签。当我想添加样式时,代码文件会给我带来错误,其中很多都是......
我想添加此
<!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)
当我将它添加到字符串中时,Visual Studio基本上强调了所有内容(上面的所有html)......
如何在ASP中格式化/设置我的电子邮件正文?
谢谢
答案 0 :(得分:1)
你必须逃避所有引用字符。有两种选择:
// 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);
答案 1 :(得分:0)
您可以使用StringBuilder.Append()
简单邮件发送代码为here