简体   繁体   中英

Opening Outlook 365 window from WPF .Net Core app

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM