使用smtp发送电子邮件发送电子邮件失败

时间:2019-10-15 02:15:23

标签: c# .net email smtp

您好,我正在尝试以c#Windows形式制作一个简单的应用程序,该应用程序将发送电子邮件,但出现此错误 无法发送邮件,当我看到内部异常时,它显示无法连接到远程服务器,我的代码有什么问题?

 private static void SendEmailReport(string strFile, string dateFrom)
        {
            try
            {

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

                msg.Subject = "Testing Email";

                msg.From = new System.Net.Mail.MailAddress("**@gmail.com");

                msg.To.Add(new System.Net.Mail.MailAddress("**@yahoo.com"));

                msg.Body = "testing the email";



                System.Net.Mail.SmtpClient smpt = new System.Net.Mail.SmtpClient();

                smpt.Host = "smtp.gmail.com";

                smpt.Port = 587;

                smpt.EnableSsl = true;

                smpt.Credentials = new System.Net.NetworkCredential("**@gmail.com", "*****");

                smpt.Send(msg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

第二个内部异常:

An attempt was made to access a socket in a way forbidden by its access permissions 74.125.24.109:587

0 个答案:

没有答案