0
votes

This question has been asked many items, but I wasn't able to find appropriate actual solution.

I am developing WPF app using .Net Core 3.1 and need to open Outlook (365, 16.0.12827.20328) window with new email and attachments. The easiest way is using Interop.

My code:

        Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
        MailItem oMsg = (MailItem)oApp.CreateItem(OlItemType.olMailItem);

        oMsg.Subject = "subject";
        oMsg.BodyFormat = OlBodyFormat.olFormatHTML;
        oMsg.HTMLBody = "body";
        oMsg.Attachments.Add("filepath", OlAttachmentType.olByValue, Type.Missing, Type.Missing);

For this I need Interop package. I tried installing nuget Microsoft.Office.Interop.Outlook and adding reference COM -> Interop.Microsoft.Office.Interop.Outlook.

In both scenarios I get 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.'

What do I have to do to solve the issue? And why I need version 15.0.0.0? Internet says that version 15 is for Outlook 2013.

1
An interop dll will be generated when you reference Outlook from the COM tab instead of using NuGet. Does that work?Dmitry Streblechenko
@DmitryStreblechenko as I've mentioned, I tried referencing COM -> Interop.Microsoft.Office.Interop.Outlook, but it gives the same errorRoman
I think you are missing my point: you can add a reference to an existing interop dll, or you can add a reference to a COM library and VS will generate an interop dll for you. I meant the latter option.Dmitry Streblechenko

1 Answers

1
votes

Typically for automating Outlook you must add the following COM references:

  • Microsoft Office type library - for common MS Office types.
  • Microsoft Office Outlook type library - for Outlook specific types.

You may try to create a new .net framework application and add these COM references. Or just try creating a new VSTO add-in and observe the added COM references.