在我的Asp.Net应用程序中,我试图使用html
标签格式化我的外发邮件,以便收件人在其电子邮件收件箱中打开邮件时看起来正确。以这个post为例,我遇到了错误。首先,我有一个通用的“实用程序”文件,其中我的sendMail
函数是使用
Utilities.cs
public static class Utility
{
public static void sendEmail(string toaddress, string bodycontent, string subjectTxt, string ccAddress)
{
string sendEmail = string.Empty;
try
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
....
}
}
}
因此,我的mailMessage.IsBodyHtml
设置为true。回到我的SendEmail.cs
文件中,将调用该文件,并在单击toaddress
时插入相应的bodycontent
,SubmitBtn
等。 bodycontent
会根据单选按钮的选择填充自动生成的字符串,然后插入textarea
。从textarea
中分配了bodycontent
。直到我在邮件中添加了`标签,它才能正常工作。
SendEmail.cs
protected void ButtonSend_Click(object sender, System.EventArgs e)
{
....
Utility.sendEmail(userEmail, SpellTextBoxNotify.Text, TextBoxSubject.Text, ccClean);
...
}
protected void uxRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable emailInfo = _emailDtr.GetTicketInfoByTicketNumber(Session["TicketNumber"].ToString());
string email = emailInfo.Rows[0]["RequestorEmail"].ToString();
string name = emailInfo.Rows[0]["RequestorName"].ToString();
string phone = emailInfo.Rows[0]["RequestorPhone"].ToString();
.....
if (uxRadioButtonList.SelectedItem.Text == "Forward")
{
TextBoxTo.Text = userEmail;
TextBoxSubject.Text = "BCA Helpline Request Detailed Response : " + s;
string new_message = "Please email:steve.mcmaster@ideationinc.com**" +
"Dear Steve,*<br />" +
"This BC Helpline inquiry has been flagged as a Tier 4 request.**<br /><br />" +
"Please see the inquiry below. This ticket will be closed out in our system. Please let us know if you’d like * <br />" +
"us to respond. **<br />" +
"Contact info: *<br />" +
name + "*<br />" +
"P: " + phone + "*<br />" +
email + "**<br /><br />" +
"Regards, **<br /><br />" + name + "(CTR) *" + "Dewberry Consultants LLC, Contractor<br />*Federal Emergency Management Agency*<br />FEMA HQ*<br />500 C. St., SW*Washington, D.C. 20472<br />*Email: " + userEmail;
new_message = new_message.Replace("*", "" + System.Environment.NewLine);
SpellTextBoxNotify.Text = new_message;
}
else if (uxRadioButtonList.SelectedItem.Text == "Interim Response")
{
...
}
....
}
}
在添加<br />
标记之前,所有方法都可以正常工作。然后,按钮onClick
功能永不触发,并且我在浏览器控制台中收到以下消息:“
Sys.WebForms.PageRequestManagerServerErrorException:一个潜在的 从客户端检测到危险的Request.Form值 (ctl00 $ ContentPlaceHolder1 $ SpellTextBoxNotify =“ ... tesinc.com
关于如何克服此问题并使html标记起作用的任何建议? “
答案 0 :(得分:1)
您的问题是,您正在通过网页上控件的Text
属性来传递HTML字符串。 Web服务器拒绝了将HTML注入页面的尝试。
一种解决方案是将TextBoxSubject.Text
保留为纯文本,并将换行符转换为ButtonSend_Click
中的HTML
protected void ButtonSend_Click(object sender, System.EventArgs e)
{
....
Utility.sendEmail(userEmail, SpellTextBoxNotify.Text, newlineToBR(TextBoxSubject.Text), ccClean);
...
}
答案 1 :(得分:1)
设置方式似乎是用户在向Web表单中输入代码,这是不可以的。
因此,将所有代码从受保护的void uxRadioButtonList_SelectedIndexChanged(对象发件人,EventArgs e)移动到受保护的void ButtonSend_Click(对象发件人,System.EventArgs e),而不必费心将文本框的文本设置为电子邮件正文。
Th