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

still getting

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

well add the custom errors message they ask you to do to your web.config file. this way we can see what your error really is!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.