我有使用.NET 3.5开发的WPF应用程序。 我试图在Windows Vista PC上运行该应用程序。 应用程序运行良好,直到它需要发送电子邮件的部分,然后应用程序停止以下错误:
Description:
Stopped working
Problem Signature:
Problem Event Name: CLR20r3
Problem Signature 01: yesmonitor.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 54c730d7
Problem Signature 04: mscorlib
Problem Signature 05: 2.0.0.0
Problem Signature 06: 53a124a5
Problem Signature 07: f50
Problem Signature 08: 7
Problem Signature 09: N3CTRYE2KN3C34SGL4ZQYRBFTE4M13NB
OS Varsion: 6.0.6002.2.2.0.768.2
Local ID: 1037
我还在PC上安装了.NET 3.5框架:
Visual C++ Redistributable 2013
Visual C++ Redistributable 2012
Visual C++ Redistributable 2008
Visual C++ Redistributable 2005
我发送邮件的代码是:
MailAddress From = new MailAddress("mymail", strIsTestPass + " - " + errorType);
MailMessage mail = new MailMessage();
mail.From = From;
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = true;
mail.To.Add("mymail");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential basicCredential = new NetworkCredential("mail", "password");
smtp.Credentials = basicCredential;
smtp.EnableSsl = true;
smtp.Send(mail);
它在Win7 OS PC上运行的方式。 可能是什么问题,我该如何解决?
答案 0 :(得分:1)
将您的代码置于try catch中,并将您的Google帐户设置“Access for less secure apps”设置为On。
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("example@gmail.com");
mail.To.Add("example@gmail.com);
mail.Subject = "email subject";
mail.Body = "Email body here";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("mail", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch (Exception)
{
throw;
}