2013-03-06 85 views
0

美好的一天。在var html = string.Format中創建html電子郵件格式

我在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

什麼是你的HTML電子郵件與「TextBoxName.Text」有關嗎? – MikeSmithDev 2013-03-06 16:35:59

+0

使用stringbuilder構造HTML格式的正文併發送郵件。請確保在代碼中將郵件正文格式屬性更改爲html。(ie,)obj.format = mailformat.html; – 2013-03-06 17:00:22

回答

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

謝謝。感謝您的回答 – 2013-03-07 05:33:52

0

您可以使用StringBulider.Append()

簡單的郵件發送代碼here