I'm trying to send an email from my contact form using gmail, but i get a runtime error when try to send it.
Heres the code:
MailMessage email = new MailMessage();
email.From = new MailAddress(from);
email.To.Add(new MailAddress(to));
email.Subject = subject;
email.Body = body;
email.IsBodyHtml = false;
System.Net.NetworkCredential auth = new System.Net.NetworkCredential("username", "password");
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = auth;
smtp.Send(email);
Any help would be appreciated!
Thanks
SiPex