Reputation: 9063
I have a basic SendMail method that works well, using System.Net.Mail and was hoping for some advice on how to send it using a hyperlink
something to the effect of
labTester.Text = <p>Please <a href='#'>Click here</a>if you haven't received a mail
This is the mail method I have been using
protected static void SendMail(string firstName, string lastName, string email, string password)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("[email protected]", "Visuals");
mailMessage.To.Add(email);
mailMessage.Subject = "Thank you for registering!";
//mailMessage.Body = "<html><body><div style=\"font-family:arial;font-size:12px\"><p>Dear " + firstName + " " + lastName + "</p><p>Your details are as follows:<ul><li><b>User Name:</b> " + email + "</li><li><b>Password:</b> " + password + "</li></ul><p>To complete The Registration,<a href=\"http://www.lrvisuals.co.za/LoginUser.aspx?IsApproved=Yes&userName="+firstName+"'>\">please click the following link</a></p></div></body></html>";
mailMessage.Body = "<html><body><div style=\"font-family:arial;font-size:12px\"><p>Dear " + firstName + " " + lastName + "</p><p>Your details are as follows:<ul><li><b>User Name:</b> " + email + "</li><li><b>Password:</b> " + password + "</li></ul><p>To complete The Registration,<a href=\"http://localhost:2482/LoginUser.aspx?IsApproved=Yes&userName=" + email + "'>\">please click the following link</a></p></div></body></html>";
mailMessage.IsBodyHtml = true;
SmtpClient mailSender = new SmtpClient(ConfigurationManager.AppSettings["smtpconn"]);
mailSender.Send(mailMessage);
}
is it even possible execute a method(Code Behind) using a hyperlink
Upvotes: 0
Views: 1315
Reputation: 1169
System.Diagnostics.Process.Start("mailto:EMAILADRESS");
Use a LinkLabel, add your methode on the OnClick event and do this.
You can add CCs, BCCs, also subject and the body. New Row with %0A
e.g.
System.Diagnostics.Process.Start("mailto:EMAILADRESS&[email protected]&[email protected]&subject=Testmail&body=Hello,%0AThis is Testmessage");
Upvotes: 1
Reputation: 787
If you're trying to call your code behind from an asp.net page, you can use a LinkButton with an OnClick event handler in your code behind.
You can't call a method in your code behind from a normal hyperlink unless you're using ajax and then things get a bit more complicated.
Upvotes: 1