Click here to Skip to main content
15,843,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,
I am working on a windows application. I am sending a mail trough gmail on a button at a form. it works fine when I run my application. but if I create Setup of this aapplication then it gives error. How i Solve it .Pls Help

Thanks in advance.....
The error which i got is

The remote certificate is invalid according to the validation procedure.

and my code is
mail.From = new MailAddress("");//My Gmail ID
                       string emp = "";
                       mail.Subject = "Confirmations of User Name && Password";
                       StreamReader reader = new StreamReader("HTMLPage1.htm");
                       string readFile = reader.ReadToEnd();
                       string myString = readFile;
                       string date = System.DateTime.Now.Date.ToShortDateString();
                       string str = PopulateBodyEnquiry(txtCmp.Text, UserName, UserName, Pwd, date);
                       mail.Body = str;
                       mail.IsBodyHtml = true;
                       SmtpClient smtp = new SmtpClient("");
                       smtp.Port = 587;
                       smtp.Host = "";
                       smtp.EnableSsl = true;
                       smtp.UseDefaultCredentials = false;
                       smtp.Credentials = new System.Net.NetworkCredential("mygmailId", "password");
                       smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                       ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                           return true;
Updated 7-Aug-14 22:33pm
Animesh Datta 8-Aug-14 3:11am    
which error ?
Raul Iloc 8-Aug-14 3:22am    
You have to provide more details (exception details, source code used for sending email,etc.) in order to can help you!
ErBhati 8-Aug-14 3:31am    
the error is "The remote certificate is invalid according to the validation procedure."

Try resetting your gmail account password. You should have a strong alpha numeric password for sending email.

Also,you should enable your application to access gmail account.[^] :-)
Share this answer
check ur gmail account u have put any second varification code in gmail please remove it..
Share this answer
I solve by myselft. when i make setup of this i not include the Html file which have the mail body. After include this it works fine. thanks
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900