MailMessage mm = new MailMessage("xyz@gmail.com", TextBoxEmail.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi ,<br /><br />Your password is .<br /><br />Thank You.");
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "xyz@gmail.com";
NetworkCred.Password = "xyz";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
message = "Registration successful. Activation email has been sent.";
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
this is my code to send email after registration is successful. it work fine on my localhost iis server. but after deploying web-site on server email is not send to user. there is
Object reference not set to an instance of an object.
error message shown. please help.
same code work on password recovery page. but here it is not working.
I did some changes in code and also create a new page for registration now it is showing a following error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
first i thought that it is error of mail sending code but it work fine on iis local server and also on other page. so i think may be it is a problem of button click event. just able to reach here. please some help me as i know i get my answer here.
my new code:
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress("xyz@gmail.com");
mail.Subject = "mailSubject";
mail.Body = "mailBody";
mail.IsBodyHtml = true;
mail.To.Add("xyz@gmail.com");
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "xyz");
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
What I have tried:
MailMessage mm = new MailMessage("xyz@gmail.com", TextBoxEmail.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi ,<br /><br />Your password is .<br /><br />Thank You.");
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "xyz@gmail.com";
NetworkCred.Password = "xyz";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
message = "Registration successful. Activation email has been sent.";
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
this is my code to send email after registration is successful. it work fine on my localhost iis server. but after deploying web-site on server email is not send to user. please help.