从 ASP.Net Core Blazor 网站与 Outlook 交互

发布于 2025-01-17 12:50:36 字数 1396 浏览 2 评论 0 原文

我正在使用大餐和剃须刀页面将旧的Silverlight应用程序转换为ASP.NET核心。

旧的应用程序正在打开前景,并创建一封电子邮件,准备与主题一起发送,以及一系列附件。它正在创建一个对象来使用以下代码来执行此操作:

Dynamic outlook = AutomationFactory.GetObject(“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站点中做到这一点的任何建议将不胜感激。

I am converting an old Silverlight application into Asp.Net Core, using Blazor and Razor Pages.

The old application is opening Outlook, and creating an email ready to send with a Subject, From etc, plus a series of attachments. It is creating an object to do this using the following code:

Dynamic outlook = AutomationFactory.GetObject(“Outlook.Application”).

In my web-site, I do something similar:

This works when running my web-site locally in Visual Studio, however I cannot deploy it to 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.

I’m assuming that I won’t be able to use this approach, however I can’t see any alternative. Any suggestions as to how I can do this in an ASP.Net Core Blazor web-site would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2025-01-24 12:50:36

您不能在服务(例如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, add X-Unsent: 1 MIME header.

拍不死你 2025-01-24 12:50:36

在我的网站中,我做了类似的事情:
使用对 Microsoft Outlook 16.0 对象库的 COM 引用。

Office 服务器端自动化的注意事项 指出以下内容:

Microsoft 目前不建议也不支持通过任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)实现 Microsoft Office 应用程序的自动化,因为 Office 可能会表现出不稳定的情况Office 在此环境中运行时的行为和/或死锁。

如果您正在构建在服务器端上下文中运行的解决方案,则应尝试使用可安全执行无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。如果您使用服务器端解决方案中的 Office 应用程序,该应用程序将缺乏许多成功运行所需的功能。此外,您还将面临整体解决方案稳定性的风险。

通过 JS 代码,您可以从 Internet Explorer 自动化 Outlook(仅在 Windows 上)。其他浏览器对 COM 技术一无所知。因此,我建议考虑其他方法来完成工作。最简单的方法,就像德米特里建议的那样,是使用 mailto 协议。它打开客户的电子邮件系统并开始一封新的电子邮件。以下示例显示了一个将准备电子邮件的链接:

<a href="mailto:[email protected]?
    subject=MessageTitle&
    body=Message Content">
    Contact Us</a>

您可以考虑使用 EWS图表API(如果您需要)静默发送电子邮件。

In my web-site, I do something similar:
Use a COM reference to the Microsoft Outlook 16.0 object library.

The Considerations for server-side Automation of Office states the following:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

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:

<a href="mailto:[email protected]?
    subject=MessageTitle&
    body=Message Content">
    Contact Us</a>

You may consider using EWS or Graph API if you need to send email silently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文