Unable to send g-mail after hosting
<p>This is my code to send email after registration is successful. It works fine on my localhost IIS server. But after deploying web-site on server email is not sent to user. There is no exception or error message shown. </p>

<pre><code>MailMessage mm = new MailMessage("xyz@gmail.com", TextBoxEmail.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi ,&lt;br /&gt;&lt;br /&gt;Your password is .&lt;br /&gt;&lt;br /&gt;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);
</code></pre>

<p>same code work on password recovery page. but here it is not working.</p>

<p>I did some changes in code and also create a new page for registration now it is showing a following error </p>

<p>Object reference not set to an instance of an object.</p>

<p>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. </p>

<p>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.</p>

<p>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.</p>

<p>my new code:</p>

<pre><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))//2nd parameter is PORT No.
                    {
                        smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "xyz");
                        smtp.EnableSsl = true;//set this as your Host Name properties, for gmail,its true
                        smtp.Send(mail);//actual sending operation here
                    }
                }
</code></pre>