7
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);

我想在发送的邮件正文中有一个超链接,上面写着“登录”。我怎样才能做到这一点?

4

5 回答 5

10
message.Body = "Please <a href=\"http://www.example.com/login.aspx\">login</a>";

确保在发送内容是 HTML 时突出显示。

message.IsBodyHTML = true;
于 2012-05-23T12:18:21.480 回答
2

将消息设置为message.IsBodyHTML = true

<a href="http://YourWebsite.Com">Login</a>
于 2012-05-23T12:18:44.460 回答
2
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
于 2012-05-23T12:19:14.447 回答
0

将消息格式化为 HTML,并确保将 MailMessage 上的 IsBodyHtml 属性设置为 true:

message.IsBodyHtml = true;

于 2012-05-23T12:19:27.840 回答
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); 

您只需将正文的格式设置为 html,然后您可以在邮件消息的 bosy 中添加 html 元素

于 2012-05-23T12:30:04.017 回答