Arianule
Arianule

Reputation: 9063

sending a mail using hyperlink

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>&nbsp;" + email + "</li><li><b>Password:</b>&nbsp;" + 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>&nbsp;" + email + "</li><li><b>Password:</b>&nbsp;" + 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

Answers (3)

DatRid
DatRid

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

drac13
drac13

Reputation: 112

Use link button Click Here to call your function

Upvotes: 1

user2444499
user2444499

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

Related Questions