Reputation: 1472
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?
Upvotes: 0
Views: 1325
Reputation: 1
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.
Upvotes: -1
Reputation: 15663
You wouldn't happen to have a firewall disallowing outbound connections here then, say, specifically allowed outlook to punch through . . .
Upvotes: 0
Reputation: 51094
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);
Upvotes: 4