【发布时间】:2026-01-10 13:35:01
【问题描述】:
我正在尝试从我的 UWP 应用程序发送电子邮件,这是我收到的错误:
$exception {System.IO.FileNotFoundException: 无法加载文件或 程序集'System.Net.Security,版本=4.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a'。系统找不到文件 指定的。文件名:'System.Net.Security,版本=4.0.0.0, 文化=中性,PublicKeyToken=b03f5f7f11d50a3a' 在 App1.glavnookno.d__10.MoveNext()} System.IO.FileNotFoundException
这是我的代码:
try
{
//From Address
string FromAddress = "rene.vucko@gmail.com";
string FromAdressTitle = "Expenses to pay";
//To Address
string ToAddress = "rene.vucko@gmail.com";
string ToAdressTitle = "Microsoft ASP.NET Core";
string Subject = "Hello World - Sending email using ASP.NET Core 1.1";
string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks ( Windows, Linux, Mac ) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end.";
//Smtp Server
string SmtpServer = "smtp.gmail.com";
//Smtp Port Number
int SmtpPortNumber = 587;
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
mimeMessage.Subject = Subject;
mimeMessage.Body = new TextPart("plain")
{
Text = BodyContent
};
using (var client2 = new SmtpClient())
{
client2.Connect(SmtpServer, SmtpPortNumber, false);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
client2.Authenticate("rene.vucko@gmail.com", "y");
client2.Send(mimeMessage);
Console.WriteLine("The mail has been sent successfully !!");
Console.ReadLine();
client2.Disconnect(true);
}
}
catch(Exception ex)
{
throw ex;
}
我启用了不太安全的应用程序,并且我没有两步验证。我正在使用 NUGET "MailKit" 发送这些邮件,因为我无法添加对 system.web.mail 的引用,因为 VS2017 说它在我的系统中不存在。
这些是我正在使用的:
using MailKit.Net.Smtp;
using MimeKit;
【问题讨论】:
-
检查您的参考资料。很有可能你有一个比实际被重新引用的更新的 nuget。在 .net 4.6 winforms 应用程序中使用更新的包(如 ValueTuple)时,我得到了这个。为了解决它,我必须在 app.config 中进行显式绑定覆盖
-
我该怎么做?
-
为什么不使用内置库?检查this
-
我的意思是 MailKit 参考在参考标签中...
-
您是在 UWP 应用中收到此错误,还是只是从服务器收到错误?