ASP.NET无法通过Gmail SMTP发送电子邮件,但Outlook 2007成功 [英] ASP.NET fails to send email through Gmail SMTP, but Outlook 2007 succeeds

查看:128
本文介绍了ASP.NET无法通过Gmail SMTP发送电子邮件,但Outlook 2007成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周前,您好所有
,我的ASP.NET网站停止发送用户评论,我通过Gmail SMTP服务器(smtp.gmail.com)将这些评论通过电子邮件发送到我的电子邮件帐户。我在开发机器上打开了项目,并在几分钟后再次发送电子邮件,但发送了以下异常消息:

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:


发送失败mail

Failure sending mail

无法从传输连接读取数据:net_io_connectionclosed。

Unable to read data from the transport connection: net_io_connectionclosed.

我正在使用端口为465的Gmail SMTP,并且MailClient.EnableSSL = True。
奇怪的是我的Office Outlook 2007使用相同的设置,并且使用相同的Gmail帐户发送邮件时没有任何问题。

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.

任何想法?

推荐答案

此代码适用于我。请注意,端口号与您正在尝试的465不同。

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);

这篇关于ASP.NET无法通过Gmail SMTP发送电子邮件,但Outlook 2007成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆