MailMessage message = new MailMessage();
message.From = new MailAddress("hkar@gmail.com");
message.Subject = "Subject";
message.Body = "Please login";
SmtpClient smtp = new SmtpClient();
message.To.Add("karaman@gmail.com");
smtp.Send(message);
我希望在已发送邮件正文中有一个超链接,其中显示“登录”。我怎么能这样做?
答案 0 :(得分:10)
message.Body = "Please <a href=\"http://www.example.com/login.aspx\">login</a>";
请确保在发送时突出显示内容为HTML。
message.IsBodyHTML = true;
答案 1 :(得分:2)
将讯息设为message.IsBodyHTML = true
<a href="http://YourWebsite.Com">Login</a>
答案 2 :(得分:2)
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
答案 3 :(得分:0)
将邮件格式化为HTML并确保将MailMessage上的IsBodyHtml属性设置为true:
message.IsBodyHtml = true;
答案 4 :(得分:0)
System.Text.StringBuildersb = new System.Text.StringBuilder();
System.Web.Mail.MailMessage mail = new System.Mail.Web.MailMessage();
mail.To = "recipient@address";
mail.From = "sender";
mail.Subject = "Test";
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
sb.Append("<html><head><title>Test</title><body>"); //HTML content which you want to send
mail.Body = sb.ToString();
System.Web.Mail.SmtpMail.SmtpServer = "localhost"; //Your Smtp Server
System.Web.Mail.SmtpMail.Send(mail);
你只需要将body的格式设置为html,然后就可以在邮件的bosy中添加html元素