[英]ASP.NET app to send an mail with a hyperlink
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);
I want to have a hyperlink in the body of sent mail where it says "login". 我希望在发送邮件正文中有一个超链接,其中显示“登录”。 How can I do that? 我怎样才能做到这一点?
message.Body = "Please <a href=\"http://www.example.com/login.aspx\">login</a>";
确保在发送时突出显示内容为HTML。
message.IsBodyHTML = true;
将消息设置为message.IsBodyHTML = true
<a href="http://YourWebsite.Com">Login</a>
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
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;
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元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.