我需要在角括号中传递一些文字,例如<头>或者<脚本>在MsgBody
部分,我无法这样做......我的代码 -
MailMessage msg = new MailMessage();
msg.Body = string.Format("<b>System Area :</b>{0}<br /><b>Assigned To : </b>{1}<br /><b>Status :</b><font color=#0000FF>{2}</font><br /><br><b>Description :</b> {3}", system_Area, Assigned_ToVal, TaskStatus, MsgBody);
答案 0 :(得分:0)
最好的选择是HtmlEncode所需的文本正文并使用&#34; @&#34;来转义整个字符串:
MailMessage msg = new MailMessage();
string system_Area_Encoded = HttpContext.Current.Server.HtmlEncode(system_Area);
string assigned_ToVal_Encoded = HttpContext.Current.Server.HtmlEncode(Assigned_ToVal);
string taskStatus_Encoded = HttpContext.Current.Server.HtmlEncode(TaskStatus);
string msgBody_Encoded = HttpContext.Current.Server.HtmlEncode(MsgBody);
msg.Body = string.Format(@"<b>System Area :</b>{0}<br /><b>Assigned To : </b>{1}<br /><b>Status :</b><font color=#0000FF>{2}</font><br /><br><b>Description :</b> {3}", system_Area_Encoded, assigned_ToVal_Encoded, taskStatus_Encoded, msgBody_Encoded);
您可以在MSDN中获得有关HtmlEncode的更多信息: https://msdn.microsoft.com/es-es/library/w3te6wfz(v=vs.110).aspx