Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

c# - SMTP Gmail timing out

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("[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>" + "
 
";
            mail.Body += "Beginning Database Count - " + begDatabaseCount + "
" + "
";
            mail.Body += "End Database Count - " + endDatabaseCount + "
" + "
";
            mail.Body += "<b>Total Imported Orders = " + (endDatabaseCount - begDatabaseCount) + "<b>" + "
" + "
";
            mail.IsBodyHtml = true;

            smtpserver.Send(mail);
        }

Port 465 = Time Out after 1 minute

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As @kostyan said, the right port is 587, but to authenticate you need to allow access from less secure apps in your gmail account. Try it here

It worked for me, hope it helps..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...