发送邮件与ASP.Net vNext [英] Sending mail with ASP.Net vNext

查看:152
本文介绍了发送邮件与ASP.Net vNext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在传统的ASP.Net和.Net一般来说,发送邮件是通过 System.Net.Mail 这住在 System.dll中类实现。现在有了KRE,vNext似乎并不具有 System.Net.Mail 作为一个单独的包。

In legacy ASP.Net and .Net in general, sending mail was accomplished via System.Net.Mail classes which resided in System.dll. Now with KRE, vNext doesn't seem to have System.Net.Mail as a separate package.

在引用 project.json

"frameworks": {
    "aspnet50": { },
    "aspnetcore50": { },
    "net453": {}       // <<< throws compilation errors
},

将导致所有的地狱冲出重围像错误:

causes all hell to break loose with errors like:

的.NET Framework 4.5.3错误CS0234:类型或命名空间名称'ASPNET'不存在命名空间'微软'(是否缺少程序集引用)存在

.NET Framework 4.5.3 error CS0234: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

这几乎抱怨所有vNext的依赖是KPM包的一部分。

It virtually complains about all vNext dependencies that are part of kpm packages.

那么,有没有人想出一个办法使用发送邮件ASP.Net vNext了吗?

So, has anyone figured out a way to send mails using ASP.Net vNext yet?

注意

虽然系统参考下,即使智能感知显示 System.Net.Mail 可供使用的出现,在code不能编译。例如,一个简单的语句就是这样,虽然看起来是有效的,

Even though System appears under References and even though Intellisense shows System.Net.Mail is available for use, the code doesn't compile. E.g., a simple statement like this, although appears valid,

using System.Net.Mail; 

var m = new MailMessage();

将抛出编译错误,例如:

will throw compilation error such as:

ASP.NET 5.0的核心错误CS0234:类型或命名空间名称'网'不命名空间中的'系统'存在(是否缺少程序集引用)

ASP.NET Core 5.0 error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)

ASP.NET 5.0的核心错误CS0246:类型或命名空间名称MAILMESSAGE'找不到(是否缺少using指令或程序集引用?)

ASP.NET Core 5.0 error CS0246: The type or namespace name 'MailMessage' could not be found (are you missing a using directive or an assembly reference?)

更新

使用最新的Visual Studio 2015年CTP 5,他们似乎有固定的智能感知故障。现在 System.Net 没有邮件命名空间了。在一个侧面说明,在vNext项目我创建VS 2015 preVIEW不再工作 - 我在主页上得到一个错误403.3!啊,喜悦测试版软件的工作!

With latest Visual Studio 2015 CTP 5, they seemed to have fixed the intellisense glitch. Now System.Net doesn't have Mail namespace anymore. On a side note, the vNext project I created with VS 2015 preview is no longer working - I get an 403.3 error on the home page! Ah, the joy of working with beta software!

推荐答案

要使用 System.Net.Mail 您的应用程序只针对 aspnet50 。在 aspnetcore50 目标没有这样的支持(至少不是现在,据我所知)。

To use System.Net.Mail your app can target only aspnet50. The aspnetcore50 target has no such support (at least, not right now, as far as I know).

您不应该曾经有你的应用程序的目标 net453 (其中,因为卢卡的评论,已经被改名反正提到的),因为ASP.NET 5应用程式别该平台在T运行。

You shouldn't ever have your app target net453 (which, as Luca mentioned in a comment, has since been renamed anyway) because ASP.NET 5 apps don't run on that platform.

一般引用任何.NET 4.0+的NuGet包或GAC参考。

An app that targets aspnet50 can generally reference any .NET 4.0+ NuGet package or GAC reference.

所以,你的情况,删除 net453 aspnetcore50 目标和 aspnet50 目标添加了一个框架参照 System.Net.Mail

So, in your case, remove the net453 and aspnetcore50 targets, and within the aspnet50 target add a framework reference to System.Net.Mail.

一个完整的替代办法是找到针对这两个 aspnet50 aspnetcore50 ,但我怀疑这样的包在这个时候存在(尽管它无疑将在未来的某个时候)。

A complete alternative would be to find some other existing NuGet package that has support for sending email in both aspnet50 and aspnetcore50, but I doubt such a package exists at this time (though it no doubt will at some point in the future).

这篇关于发送邮件与ASP.Net vNext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆