从 ASP.Net Core Blazor 网站与 Outlook 交互
我正在使用大餐和剃须刀页面将旧的Silverlight应用程序转换为ASP.NET核心。
旧的应用程序正在打开前景,并创建一封电子邮件,准备与主题一起发送,以及一系列附件。它正在创建一个对象来使用以下代码来执行此操作:
Dynamic outlook = AutomationFactory.GetObject(“Outlook.Application”).
在我的网站中,我做类似的事情:
- 使用com引用对Microsoft Outlook 16.0对象库。
- 如果Outlook已经在运行,请根据 https://renenyfenegger.ch/notes/notes/microsoft/microsoft/microsoft/dot-nets/namespaces-class-classes/system/system/runtime/runtime/runtime/interime/interime/interime/interime/interime/interime/inthal/getactiveviveviveiveviveobebtime/marshal/getactiveobecte 。
- 否则,请使用
Microsoft.office.interop.outlook.application appOutlook = new Microsoft.office.interop.outlook.application();
创建一个对象
。但是,我无法将其部署到Azure:
C:\Program Files\dotnet\sdk\6.0.201\Microsoft.Common.CurrentVersion.targets(2926,5): Error : MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details.
我假设我无法使用这种方法,但是我看不到任何选择。关于我如何在ASP.NET Core Blazor Web站点中做到这一点的任何建议将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能在服务(例如IIS)中使用Outlook或任何其他Office应用程序。即使您确实设法运行它,它也不会帮助您 - 您的代码在服务器上运行,并且您填充和显示的消息将在服务器上,没有人会看到它。
您可以使用
mailto:
链接(它支持地址,主题和身体),或者(如果您需要HTML和/或附件),请动态创建EML(MIME)文件 - 客户端上的Outlook一面很乐意打开它。为了确保消息是可编辑的,请添加x-nosent:1
mime标头。You cannot use Outlook, or any other Office app, in a service (such as IIS). Even if you do manage to make it run, it won't help you - your code is running on the server, and the message you populate and display will be on the server, where nobody would ever see it.
You can either use a
mailto:
link (it supports address, subject, and body) or (if you need HTML and/or attachments), dynamically create an EML (MIME) file - Outlook on the client side will be happy to open it. To make sure the message is editable, addX-Unsent: 1
MIME header.Office 服务器端自动化的注意事项 指出以下内容:
通过 JS 代码,您可以从 Internet Explorer 自动化 Outlook(仅在 Windows 上)。其他浏览器对 COM 技术一无所知。因此,我建议考虑其他方法来完成工作。最简单的方法,就像德米特里建议的那样,是使用 mailto 协议。它打开客户的电子邮件系统并开始一封新的电子邮件。以下示例显示了一个将准备电子邮件的链接:
您可以考虑使用 EWS 或 图表API(如果您需要)静默发送电子邮件。
The Considerations for server-side Automation of Office states the following:
From a JS code you can automate Outlook from Internet Explorer (only on Windows). Other browsers don't know anything about the COM technology. So, I'd suggest considering other approaches for getting the work done. The easiest way, like Dmitry suggested, is to use the mailto protocol. It opens a client's e-mail system and begins a new email message. The following example shows a link that will prepare an e-mail message:
You may consider using EWS or Graph API if you need to send email silently.