private string sendEmail(string emailId,string userID)
{
try
{
userID = Encrypt(userID);
MailMessage mail = new MailMessage();
mail.To.Add(emailId);
mail.From = new MailAddress("");
//mail.Subject = "Your password for account " + emailId;
string userMessage = "http://localhost/LoginWithSession/ResetPassword" + userID;
userMessage = userMessage + "<br/><b>User Id:</b> " + emailId;
//userMessage = userMessage + "<br/><b>Passsword: </b>" + password;
string Body = "<br/><br/>Please click on link to reset your password:<br/></br> " + userMessage + "<br/><br/>Thanks";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //SMTP Server Address of gmail
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("harianasaif@gmail.com", "test");
// Smtp Email ID and Password For authentication
smtp.EnableSsl = true;
smtp.Send(mail);
return userMessage;
}
catch (Exception ex)
{
return "Error............" + ex;
}
}
**1. This is my code to send email
Problem is I cannot open Reset Page when clicked on URL
I have created the virtual directory as well**
Please check this Here you need to add <a>
tag for called the URL.
//Create one function for getting URL run time like localhost or any domain name
public string GetUrl()
{
var request = Request;
return string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, (new System.Web.Mvc.UrlHelper(request.RequestContext)).Content("~"));
}
private string sendEmail(string emailId,string userID)
{
try
{
userID = Encrypt(userID);
MailMessage mail = new MailMessage();
mail.To.Add(emailId);
mail.From = new MailAddress("");
//mail.Subject = "Your password for account " + emailId;
string userMessage = string.Concat("<a href='",GetUrl(), "LoginWithSession/ResetPassword/", userID,"'>");
userMessage = userMessage + "<br/><b>User Id:</b> " + emailId+"</a>";
//userMessage = userMessage + "<br/><b>Passsword: </b>" + password;
string Body = "<br/><br/>Please click on link to reset your password:<br/></br> " + userMessage + "<br/><br/>Thanks";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //SMTP Server Address of gmail
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential();
// Smtp Email ID and Password For authentication
smtp.EnableSsl = true;
smtp.Send(mail);
return userMessage;
}
catch (Exception ex)
{
return "Error............" + ex;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.