SMTP服务器发送邮件时出错

SMTP服务器发送邮件时出错

本文介绍了使用Gmail SMTP服务器发送邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



尝试使用gmails SMTP服务器发送电子邮件时,出现以下错误:

服务不可用,正在关闭传输通道.服务器响应为:无法连接到SMTP服务器173.194.67.108(173.194.67.108:587),连接超时"

我的代码如下:

Hi,

When trying to send an email using gmails SMTP server I get the following error:

"Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 173.194.67.108 (173.194.67.108:587), connect timeout"

My code is as follows:

System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();

                email.To.Add(new MailAddress("User_To"));
                email.From = new MailAddress("User_From");
                email.Subject = "Question";
                email.Body = "Boody";

                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.EnableSsl = true;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;

                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential("myGmailAccountEmail", "myGmailAccountPassword");
                client.Send(email);

推荐答案

MailAddress mailfrom = new MailAddress ( "[email protected]" );
            MailAddress mailto = new MailAddress ( "[email protected]" );
            MailMessage newmsg = new MailMessage ( mailfrom, mailto );

            newmsg.Subject = "Subject of Email";
            newmsg.Body = "Body(message) of email";

            ////For File Attachment, more file can also be attached

            //Attachment att = new Attachment ( "G:\\code.txt" );
            //newmsg.Attachments.Add ( att );

            SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
            smtps.UseDefaultCredentials = false;
            smtps.Credentials = new NetworkCredential ( "[email protected]", "pwd" );
            smtps.EnableSsl = true;
            smtps.Send ( newmsg );


SmtpClient client = new SmtpClient("smtp.gmail.com");


代替


instead of

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);



这篇关于使用Gmail SMTP服务器发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:21