0
votes

I am trying to read an office template (.oft file) with embedded images in the body of the email. I tried using the MsgReader nuget package which reads the contents, but cant manage the images in the body.

I have also tried using Microsoft.Office.Interop.Outlook, but this throws the following error at runtime :

Error: System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified. File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

I am struggling to find a solution to this. On my work computer i have Office 365 installed. in the about tab is says Microsoft Outlook for Microsoft 365 MSO (16.0.12827.20200) 32-bit

So far based on what i have read, i have tried running my prototype project in IIS instead of IIS Express, but this did not resolve the problem. Do I need to install a specific version of Outlook, or some redistribution files? Or is there a better way to do this?

3

3 Answers

0
votes

Error: System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified. File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

It seems you just need a reference to the office.dll assembly as well. For example, search for the Microsoft Office library in the COM references section:

Add a COM reference dialog window

Also, I've noticed that you are running the solution under IIS.

So far based on what i have read, i have tried running my prototype project in IIS instead of IIS Express, but this did not resolve the problem.

Here is what Microsoft states for that:

All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.

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.

Read more about that in the Considerations for server-side Automation of Office article.

Your choices are listed below:

  • Use a low-level API that can be run under a service - Extended MAPI or EWS, see Start using web services in Exchange for more information.
  • Use third-party components designed for the server-side execution.

Note, the [MS-OXMSG]: Outlook Item (.msg) File Format is described in MSDN.

0
votes

I was not able to get he interop to work, but found a working third party solution : https://downloads.aspose.com/email/net

this nuget package will read the body content including images corretly without the need for using interop.

0
votes

When using interop types with .NET Core, use a COM reference to the particular Office Object Library instead of the NuGet package:

enter image description here

enter image description here

And set Embed Interop Types and Copy Local to Yes:

3

See .NET core 3.0 and MS Office Interop for more details.