Unable to read data from the transport connection?

Viewed 29106

This is my first post on Stack, and I've literally just started programming, so please, be patient.

I'm attempting to send an email to "x" email address when Button 1 is pressed. I've looked around, and every thread is jargon-heavy and not in my context. Please pardon me if this is a "newb' question, or if it's already thouroughly answered somewhere else.

The error I'm getting is " Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed."

Here's my code

 using (SmtpClient smtp = new SmtpClient())
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 465;
            smtp.Credentials = new NetworkCredential("myemail", "mypassword");
            string to = "toemail";
            string from = "myemail";
            MailMessage mail = new MailMessage(from, to);
            mail.Subject = "test test 123";
            mail.Body = "test test 123";
            try
            {
                smtp.Send(mail);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
                            ex.ToString());
            }

Any help is greatly appreciated!

1 Answers
Related