Reputation: 395
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?
Upvotes: 7
Views: 38756
Reputation: 4459
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
Upvotes: 2
Reputation: 698
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
Upvotes: 0
Reputation: 44
Format the message as HTML and make sure to set the IsBodyHtml property on the MailMessage to true:
message.IsBodyHtml = true;
Upvotes: 0
Reputation: 70776
Set the message to message.IsBodyHTML = true
<a href="http://YourWebsite.Com">Login</a>
Upvotes: 2
Reputation: 18810
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.
message.IsBodyHTML = true;
Upvotes: 10