【发布时间】:2017-08-09 04:34:51
【问题描述】:
我只想发送一封带有超链接的电子邮件,但它一直显示为纯文本:
按钮点击:
protected void Button1_Click(object sender, EventArgs e)
{
currURL = Request.Url.Authority + HttpContext.Current.Request.ApplicationPath;
string emailSubject = "Hello World";
string emailBody = "Please click <a href='" + currURL "'>HERE</a>" Debug: " + currURL;
myClass.SendEmail(tb_EmailTo.Text, emailSubject, emailBody);
}
发送电子邮件的代码:
public static void SendEmail(string sendTo, string subject, string body, bool isBodyHTML = true)
{
SmtpClient Smtp_Server = new SmtpClient();
MailMessage e_mail = new MailMessage();
Smtp_Server.UseDefaultCredentials = false;
Smtp_Server.Credentials = new System.Net.NetworkCredential(---, ---);
Smtp_Server.Port = thePort;
//Smtp_Server.EnableSsl = True
Smtp_Server.Host = theHost;
e_mail = new MailMessage();
e_mail.From = new MailAddress(theSendFromAddress);
e_mail.To.Add(sendTo);
string currPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
string currURL = HttpContext.Current.Request.Url.AbsoluteUri.Replace(currPathAndQuery, "/");
e_mail.Subject = subject;
e_mail.IsBodyHtml = true;
e_mail.Body = body;
Smtp_Server.Send(e_mail);
}
电子邮件的正文是:
请点击这里调试:localhost:12345/
这里应该是一个指向 localhost:12345/ 的超链接,但它一直显示为纯文本。
【问题讨论】: