0
votes

Hi all a couple weeks ago, my ASP.NET website stopped sending user comments which I implemented by emailing those comments to my email account through Gmail SMTP server (smtp.gmail.com). I opened the project on my development machine and again it fails to send the email after a couple minutes with the following exception message:

Failure sending mail

Unable to read data from the transport connection: net_io_connectionclosed.

I'm using Gmail's SMTP with port 465, and MailClient.EnableSSL = True. The weird thing is my Office Outlook 2007 is using the same settings and it doesn't have any problems sending mail using the same Gmail account.

Any thoughts?

3
To clarify, it was working in your production env. but is now not working in either prod or locally?Jace Rhea
It was working just fine everywhere. 2 weeks ago we realized the site is problematic; when we checked we realized that it no longer works, neither on the production server nor locally. Then I used my Office Outlook 2007 to see if there is a problem in my local connection or gmail isacting up, and it sends mail just fine (using the same mail account we use in the web site).TheAgent

3 Answers

4
votes

This code works for me. Note the port number is different to the 465 you are trying. I'm almost certain I also tried 465 first with no luck.

var msg = new MailMessage(new MailAddress(recipient, "SCS Web Site"), new MailAddress(toAddress))
                {
                    Body = BuildMailBody(),
                    Subject = "SCS Web Site Message"
                };
var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(myGmailUser, myGmailPassword)
                };
smtp.Send(msg);
0
votes

You wouldn't happen to have a firewall disallowing outbound connections here then, say, specifically allowed outlook to punch through . . .

-1
votes

One oddity I found with formmail going through gmail (on Windows server) was that the port number was the problem. My code was similar to yours, but it only worked when I changed the port to 25 rather than the 587 or 465. That might be what you need here.