C# 使用超链接发送邮件的 ASP.NET 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10719722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET app to send an mail with a hyperlink
提问by Karaman
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.Subject = "Subject";
message.Body = "Please login";
SmtpClient smtp = new SmtpClient();
message.To.Add("[email protected]");
smtp.Send(message);
I want to have a hyperlink in the body of sent mail where it says "login". How can I do that?
我想在发送的邮件正文中有一个超链接,上面写着“登录”。我怎样才能做到这一点?
采纳答案by Lloyd Powell
message.Body = "Please <a href=\"http://www.example.com/login.aspx\">login</a>";
Make sure you highlight when sending that the content is HTML though.
确保在发送内容是 HTML 时突出显示。
message.IsBodyHTML = true;
回答by Darren
Set the message to message.IsBodyHTML = true
将消息设置为 message.IsBodyHTML = true
<a href="http://YourWebsite.Com">Login</a>
回答by dtsg
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
回答by Chris Stater
Format the message as HTML and make sure to set the IsBodyHtml property on the MailMessage to true:
将消息格式化为 HTML,并确保将 MailMessage 上的 IsBodyHtml 属性设置为 true:
message.IsBodyHtml = true;
message.IsBodyHtml = true;
回答by Zlatan
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);
You just have to set the format of body to html then you can add html element within the bosy of mail message
您只需要将 body 的格式设置为 html,然后您就可以在邮件消息的 bosy 中添加 html 元素

