Reputation: 537
I want to provide a link within Mail Message object. Tried googling couldnot find something which is simple and better. I have the following code
public ActionResult Register(Customer customer)
{
if (ModelState.IsValid)
{
var count = db.Customers.Where(x => x.Email == customer.Email).Count();
if (count > 0)
{
@ViewBag.Error = "This mail already exists";
return View();
}
db.Customers.Add(customer);
db.SaveChanges();
MailMessage msgobj = new MailMessage();
SmtpClient serverobj = new SmtpClient();
serverobj.Credentials = new NetworkCredential(customer.Email,customer.Password);
serverobj.Port = 587;
serverobj.Host = "Smtp.gmail.com";
serverobj.EnableSsl = true;
msgobj.From = new MailAddress(customer.Email, "Shopper's Stop", System.Text.Encoding.UTF8);
msgobj.To.Add(customer.Email);
msgobj.Subject = "Account Activate Link";
msgobj.Body = GetFormattedMessageHTML(customer);
msgobj.IsBodyHtml = true;
msgobj.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
serverobj.Send(msgobj);
return RedirectToAction("Products", "Home");
}
return View();
}
private String GetFormattedMessageHTML(Customer customer)
{
return "<!DOCTYPE html> " +
"<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
"<head>" +
"<title>Email</title>" +
"</head>" +
"<body style=\"font-family:'Century Gothic'\">" +
"<h1 style=\"text-align:center;\"> " + "</h1>" +
"<h2 style=\"font-size:14px;\">" +
"Name : " + customer.First_Name + " " + customer.Last_Name + "<br />" +
"Company : " + "NewTech Software" + "<br />" +
"Email : " + customer.Email + "<br />" +
//similar to this
//and when clicked how to perform further action
"Activation Link" + "<a href="+"some link"+"sometext to be clicked"+customer.Cust_Id +"></a>"+
"</h2>" +
"</body>" +
"</html>";
}
Can anyone plz help me. Above code is working fine but I am unable to generate link and also what else shoud be passed aong with cust_Id to verify upon click. Thanks
Upvotes: 0
Views: 152
Reputation: 5071
Try this
Replace
"<a href="+"some link"+"sometext to be clicked"+customer.Cust_Id +"></a>"
to
"<a href=\""+your_url+"\">clickable text</a>"
and here string your_url="";
Upvotes: 1