MailMessage message = new MailMessage();
message.From = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50383b312210373d31393c7e333f3d">[email protected]</a>");
message.Subject = "Subject";
message.Body = "Please login";
SmtpClient smtp = new SmtpClient();
message.To.Add("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43282231222e222d03242e222a2f6d202c2e">[email protected]</a>");
smtp.Send(message);
I want to have a hyperlink in the body of sent mail where it says “login”. How can I do that?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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;
Method 2
Set the message to message.IsBodyHTML = true
<a href="http://YourWebsite.Com" rel="nofollow noreferrer noopener">Login</a>
Method 3
message.Body = string.Format("Click <a href='{0}'>here</a> to login", loginUrl);
Method 4
Format the message as HTML and make sure to set the IsBodyHtml property on the MailMessage to true:
message.IsBodyHtml = true;
Method 5
System.Text.StringBuildersb = new System.Text.StringBuilder();
System.Web.Mail.MailMessage mail = new System.Mail.Web.MailMessage();
mail.To = "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="760413151f061f1318023617121204130505">[email protected]</a>";
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0