Using System.Net.Mail in ASP NET MVC 6 project

风流意气都作罢 提交于 2019-12-05 01:17:16

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.)

Since you don't need .Net Core, you can remove the dnxcore50 entry from your frameworks in your project.json.

As of today, it is now possible to send email on dnxcore50 in addition to net451 (and lots of other platforms) using MailKit

I'm using rc1 of ASP.NET 5 and I added these dependencies to my project.json to bring in the needed nugets

"MimeKit": "1.3.0-beta1",
"MailKit": "1.3.0-beta1"

So the lack of System.Net.Mail in dnxcore50 is no longer a problem, the MailKit library is actually much more feature rich than any of the old System.Net.Mail stuff.

Huge Thanks to Jeffrey Stedfast for his hard work.

For .NET Core be sure to obtain MailKit by updating project.json to add it as a dependency...

"MailKit": "~1.6.0"

See MailKit on GitHub for a complete example: https://github.com/jstedfast/MailKit

If you have set up your project in Visual Studio 2017, then this solution will work:

  1. Edit the .csproj file of your project. Right-click on the project name and choose 'Edit Project1.csproj' (in case your project name is Project1). The project's XML file opens. Change the 'TargetFramework' to net452 and add a 'RuntimeIdentifier' tag with value win7-x86. So it looks like this:

    [PropertyGroup] [TargetFramework]net452[/TargetFramework] [RuntimeIdentifier]win7-x86[/RuntimeIdentifier] [/PropertyGroup]

(replace all brackets bij 'less than' and 'greater than' signs) Your project will be linked to the .NET Framework 4.5.2 and all libraries will be available then, including the System.NET.Mail namespace.

For me, this is a working solution...:-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!