我正在尝试从我的UWP应用程序发送电子邮件,这是我收到的错误:
$ exception {System.IO.FileNotFoundException:无法加载文件或 assembly&System; Net.Security,Version = 4.0.0.0,Culture = neutral, 公钥= b03f5f7f11d50a3a&#39 ;.系统找不到该文件 指定。文件名:' System.Net.Security,Version = 4.0.0.0, Culture = neutral,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;
答案 0 :(得分:0)
解决,改为使用EAMail。这个对我说VS2017不起作用。