SMTP的Gmail超时 [英] SMTP Gmail timing out

查看:698
本文介绍了SMTP的Gmail超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道为什么发生这种情况。每一个地方我已经搜索告诉我,我这样做的权利。但每次我尝试发送邮件,它超时的 smtpserver.Send(邮件)

Not sure why this is happening. Every where I've search tells me that i'm doing this right. But every time I try and send the mail, it times out on the 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("mtaylor@atr.com", "password");
            smtpserver.UseDefaultCredentials = false;
            mail = new MailMessage();
            mail.From = new System.Net.Mail.MailAddress("mtaylor@atr.com", "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分钟后

Port 465 = Time Out after 1 minute

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

Port 587 = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. "

推荐答案

这线程帮助了我。我不知道为什么这个代码工作,我的是不是。

This thread helped me. I'm not sure why this code worked and mine wasn't.

通过Gmail

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
           {
               Host = "smtp.gmail.com",
               Port = 587,
               EnableSsl = true,
               DeliveryMethod = SmtpDeliveryMethod.Network,
               UseDefaultCredentials = false,
               Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
           };
using (var message = new MailMessage(fromAddress, toAddress)
                     {
                         Subject = subject,
                         Body = body
                     })
{
    smtp.Send(message);
}

这篇关于SMTP的Gmail超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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