我只想发送一封带有超链接的电子邮件,但它仍然显示为纯文字:
按钮点击:
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 /
HERE应该是一个指向localhost的超链接:12345 /但它仍然只是一个纯文本。
答案 0 :(得分:0)
没关系,结果发现链接:currURL给出了问题,将http://添加到它并且它有效