Click here to Skip to main content
15,945,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wanna send email from smtp server with gmail but I get the error that I dont know what is happened
content of error:
The remote certificate is invalid according to the validation procedure.
and this is my code
protected void SendMail(string from, string to, string cc, string bcc, string subject, string body)
    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress(from, "your name");
    if (cc != null)
    if (bcc != null)
    mailMessage.Subject = subject;
    mailMessage.IsBodyHtml = true;
    mailMessage.Body = body;
    mailMessage.Priority = MailPriority.Normal;
    SmtpClient client = new SmtpClient("", 587);
    NetworkCredential info = new NetworkCredential("", "123123");
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.Credentials = info;
    client.EnableSsl = true;

protected void Button1_Click(object sender, EventArgs e)

    SendMail("", "", null, null, "new mail", "Send Mail with Gmail");

Updated 13-Mar-12 16:17pm

  protected void SendMail(object sender, EventArgs e)

          System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(@ConfigurationSettings.AppSettings["EmailFrom"]);
          smtpClient.Host = @ConfigurationSettings.AppSettings["MailServerName"];
          smtpClient.Port = Convert.ToInt32(@ConfigurationSettings.AppSettings["Port"]);
          message.From = fromAddress;
          message.Subject = @ConfigurationSettings.AppSettings["EmailSubject"];
          message.IsBodyHtml = false;
          message.Body = " Any Message Text.....";


  <add key="Port" value="587"/>
  <add key="MailServerName" value=""/>
  <add key="EmailFrom" value=""/>
  <add key="EmailPassword" value="pass@123"/>
  <add key="EmailTo" value=""/>
  <add key="EmailSubject" value="My Email Subject"/>

Share this answer
Sometimes certificate errors occur due to the invalid date time settings in the system clock. Make sure that it is the current date and time.
I dont see any problem in your code...
Share this answer
try this,

MailAddress mailfrom = new MailAddress ( "" );
MailAddress mailto = new MailAddress ( "" );
MailMessage newmsg = new MailMessage ( mailfrom, mailto );

newmsg.Subject = "Subject of Email";
newmsg.Body = "Body(message) of email";

////For File Attachment, more file can also be attached

Attachment att = new Attachment ( "G:\\code.txt" );
newmsg.Attachments.Add ( att );

SmtpClient smtps = new SmtpClient ( "", 587 );
smtps.UseDefaultCredentials = false;
smtps.Credentials = new NetworkCredential ( "", "pwd" );
smtps.EnableSsl = true;
smtps.Send ( newmsg );
Share this answer
This user doesn't have a account (
First make it or use different id.
Share this answer
behrad110 4-Mar-12 13:58pm    
it is for sample but i have a valid user for yahoo
jeetveer 4-Mar-12 14:13pm    
your cod is working and there is no error when i use different e-mail id.
and i also see that when i send a mail on "" that time error message occur and that is "This user doesn't have a account ( "
how i can retrive the mail which is become an our mail account o our application usind c#
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