Click here to Skip to main content
15,936,247 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
i trying to simple develop website and i need to add sending email in it

i try many format of codes, but still i get same problem
the problem that I face says:
in Chrome browser : The remote certificate is invalid according to the validation procedure.
in Firefox & Internet Explorer : Failure sending mail.

This is the code ,, and i saw that in youtube and it is working with the person who write it ,, but I don't know what is the problem with my project ..

The Code :

MailMessage msg = new MailMessage();
            MailAddress to = new MailAddress(Label24.Text.ToString(), " Trainig Management System");
            MailAddress from = new MailAddress(Label15.Text.ToString());
            msg.From = from;
            msg.Subject = Label20.Text.ToString();
            msg.Body = Label23.Text.ToString();
            msg.IsBodyHtml = true;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;

            // to read mail information smtp simple transfer protocol
            SmtpClient client = new SmtpClient();
            client.Host = "";   // google smtp setting
            client.Port = 587;

            // to get the 'from' address details ( user name + password) 
            System.Net.NetworkCredential myaccount = new NetworkCredential(Label15.Text.ToString(), TextBox1.Text.ToString());
            client.Credentials = myaccount;
            client.EnableSsl = true;  // encription, make it secure (the sender infromation) 
            client.UseDefaultCredentials = false;

                Server.Transfer("end_message.aspx", true);
            catch (Exception ex)
                Label19.Text = ex.Message;
Arkadeep De 6-Apr-15 12:59pm    
You might get a mail from Google on the mail id, which one you are using. You have to do couple of clicks and your error should be gone.
Member 11193774 6-Apr-15 17:03pm    
i'm using gmail for both (sender and receiver ) , i get the error when i run the website. from catch part i get error message says : The remote certificate is invalid according to the validation procedure.

sorry , but what did you mean by do couple of click ?
[no name] 7-Apr-15 1:52am    

As per the error message "The remote certificate is invalid according to the validation procedure." in one of your comments above, you may want to perform these diagnostic steps[^]. Also ensure that the system's date and time are correct.

Hope this helps.
Share this answer
Member 11193774 7-Apr-15 6:44am    
i have already apply all those steps. But still i get the same error . is it something related to code or to my browser ? i really want to solve this
Agent__007 7-Apr-15 6:56am    
Did you check the system's date and time? If they are correct, check this answer out: "". "Do not use that workaround in your production code". If that works, contact your SysAdmins/STGs/IT department to get a valid/trusted certificate.
Please remove Google authentication 2-step verification and try again ..
Share this answer
Member 11193774 7-Apr-15 6:46am    
sorry ,, which step do you mean ?
Is it this one : client.Host = ""; ?
Padam Agrawal 7-Apr-15 7:12am    
if sender email has 2 step Google verification then remove/deactivate then try..

search how deactivate Google authentication 2-step verification
Member 11193774 7-Apr-15 7:53am    
i turn off verification , still i get the same error
Share this answer
Member 11193774 7-Apr-15 6:50am    
for which gmail should i apply that ? sender or receiver ,
actually i'm trying to send mail from website by using user mail to Admin mail
Padam Agrawal 7-Apr-15 7:10am    
you have to setup sender email details.
Member 11193774 7-Apr-15 7:54am    
i did that , but still i got the same error
Padam Agrawal 7-Apr-15 8:15am    
Contact at
Seems your SMTP server don't have certificate. try once EnableSSL= false
Share this answer
Deepu S Nair 15-Apr-15 6:46am    
Two solutions for a single question?Please use 'Improve Solution' link to update your existing solution.

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