ASP.NET fails to send email through Gmail SMTP, bu

2019-08-29 05:42发布

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条回答
贪生不怕死
2楼-- · 2019-08-29 05:52

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.

查看更多
Juvenile、少年°
3楼-- · 2019-08-29 06:00

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);
查看更多
Emotional °昔
4楼-- · 2019-08-29 06:10

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

查看更多
登录 后发表回答