2012-05-23 32 views
6
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); 

我想在發送郵件的正文中指出「登錄」的超鏈接。我怎樣才能做到這一點?ASP.NET應用程序發送帶有超鏈接的郵件

+0

的bosy中添加HTML元素,使用HTML:'login' –

+0

確保身體類型是HTML,然後只發送HTML。 – asawyer

回答

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

請務必在發送內容爲HTML時突出顯示。

message.IsBodyHTML = true; 
2

設置消息message.IsBodyHTML = true

<a href="http://YourWebsite.Com">Login</a> 
2
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl); 
+0

很高興看到適合單獨生成的URL的示例,而不是使用硬編碼的參考。 –

0

格式的消息爲HTML,並確保對在MAILMESSAGE IsBodyHtml屬性設置爲true:

message.IsBodyHtml =真;

0
System.Text.StringBuildersb = new System.Text.StringBuilder(); 
System.Web.Mail.MailMessage mail = new System.Mail.Web.MailMessage(); 
mail.To = "[email protected]"; 
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,那麼你可以如果身體HTML郵件

相關問題