使用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 ( "frommail@gmail.com" );
            MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
            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 ( "mail@gmail.com", "pwd" );
            smtps.EnableSsl = true;
            smtps.Send ( newmsg );


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


代替


instead of

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


请检查以下网址,

使用Google Apps发送邮件 [
Please check the following url,

Send mail using Google Apps[^]

If you are sending email from gmail or google apps than all sent email would be store in the sent items of the gmail.
Hope this may help you...