This is my code (added the above line) but still getting same error:
protected void Button1_Click(object sender, EventArgs e) { // Create a message and set up the recipients. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); message.To.Add("mymail@domain.com"); message.Subject = "Form - "; message.IsBodyHtml = true; message.Priority = MailPriority.High; message.Body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; message.Body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">"; message.Body += "</HEAD><BODY>"; message.Body += "<table border='1'><tr><td>Textbox1.Text</td><td>Textbox2.Text</td></tr><tr><td>Textbox3.Text</td><td>Textbox4.Text</td></tr></table>"; message.Body += "</BODY></HTML>"; // Send the message. smtpClient.Port = 587; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential("mygmailusername@gmail.com", "password"); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; smtpClient.Send(message); EmailSentForm.Visible = Visible; }