ASP.NET application for sending hyperlink mail

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 the sent mail, which says "login". How can i do this?

+6
source share
5 answers
 message.Body = "Please <a href=\"http://www.example.com/login.aspx\">login</a>"; 

Make sure you highlight the HTML content when submitting.

 message.IsBodyHTML = true; 
+9
source

Set message.IsBodyHTML = true

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

Format the message as HTML and verify that the IsBodyHtml property in MailMessage is true:

message.IsBodyHtml = true;

0
source
  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 need to set the body format to html, then you can add the html element to the bosy message from the mail message

0
source

Source: https://habr.com/ru/post/916446/


All Articles