System.dll中发生了类型为'System.Net.Mail.SmtpException'的未处理的异常

时间:2019-01-31 09:16:25

标签: c# smtp

System.dll中发生了'System.Net.Mail.SmtpException'类型的未处理异常

其他信息:发送邮件失败。 我在执行时遇到上述错误:

           var smtp = new SmtpClient
            {

                Host = "smtp.gmail.com",
                Port = 25, (tried with 587 also)
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(mail_From, from_Password)
                //,
                //Timeout = 200
            };
            MailMessage message = new MailMessage();
            message.IsBodyHtml = true;
            message.Subject = "DeleteDuplicateDevicesReport";
            message.Body = bodyStructure;
            message.From = new MailAddress(mail_From.ToString());
            message.To.Add(mail_To);
            smtp.Send(message);
            connection.Close();

这将通过smtp服务器发送邮件

0 个答案:

没有答案