不知道为什么会这样。我搜索过的每一个地方都告诉我我做对了。但是每次我尝试发送邮件时,它都会在 smtpserver.Send(mail) 上超时

private void emailReport(string email_address,int begDatabaseCount, int endDatabaseCount)
        {
            SmtpClient smtpserver = new SmtpClient();
            MailMessage mail = new MailMessage();
            smtpserver.EnableSsl = true;
            smtpserver.Port = 465;
            smtpserver.Host = "smtp.gmail.com";
            smtpserver.Credentials = new NetworkCredential("[email protected]", "password");
            smtpserver.UseDefaultCredentials = false;
            mail = new MailMessage();
            mail.From = new System.Net.Mail.MailAddress("[email protected]", "ATR Reports");
            mail.To.Add(email_address);
            mail.Subject = "FNAS Report - " + DateTime.Now;
            mail.Body += "<u><b>FNAS Report for " + DateTime.Now + "</u></b>" + "\r\n \r\n";
            mail.Body += "Beginning Database Count - " + begDatabaseCount + "\r\n" + "\r\n";
            mail.Body += "End Database Count - " + endDatabaseCount + "\r\n" + "\r\n";
            mail.Body += "<b>Total Imported Orders = " + (endDatabaseCount - begDatabaseCount) + "<b>" + "\r\n" + "\r\n";
            mail.IsBodyHtml = true;

            smtpserver.Send(mail);
        }

端口 465 = 1 分钟后超时

端口 587 = "SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。"

最佳答案

正如@kostyan 所说,正确的端口是 587,但要进行身份验证,您需要允许来自 Gmail 帐户中安全性较低的应用程序的访问。
试试看 here

它对我有用,希望它有帮助..

关于c# - SMTP Gmail 超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19932981/

10-16 07:13