在ASP NET MVC 6项目中使用System.Net.Mail [英] Using System.Net.Mail in ASP NET MVC 6 project
问题描述
我在ASP NET 5项目中创建简单的模拟邮件发件人时遇到麻烦.
I have trouble creating a simple mock mail sender within an ASP NET 5 project.
方法:
public static Task SendMail(string Email, string Subject, string Body)
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = "C:\\TMP";
MailAddress from = new MailAddress("jane@contoso.com", "Jane " + (char)0xD8 + " Clayton", System.Text.Encoding.UTF8);
MailAddress to = new MailAddress(Email);
MailMessage message = new MailMessage(from, to);
message.Body = Body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = Subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
client.Send(message);
message.Dispose();
return Task.FromResult(0);
}
我已经包含了依赖项'System.Net.Mail',但是工具提示说该库在DNX 4.5.1中可用,但在DNX Core 5.0中不可用,并且该项目将无法编译.
I have included the dependency 'System.Net.Mail', but a tooltip says that the library is available in DNX 4.5.1 but not in DNX Core 5.0, and the project will not compile.
在我的project.json中有:
In my project.json there is :
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
推荐答案
我不认为SmtpClient已移植到.Net Core. (您可以使用非官方反向软件包查找查找新的NuGet软件包,但没有一个.)
I don't believe that the SmtpClient is being ported to .Net Core. (You can use the unofficial reverse package lookup to find the new NuGet packages, and there isn't one.)
由于不需要.Net Core,因此可以从project.json中的frameworks
中删除dnxcore50
条目.
Since you don't need .Net Core, you can remove the dnxcore50
entry from your frameworks
in your project.json.
这篇关于在ASP NET MVC 6项目中使用System.Net.Mail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!