Reputation: 79
I am new to Visual Studio 2017 and c#. My goal is to open a new Outlook window by clicking a button in a small program I wrote for learning reasons. The problem is that, as far as I know, the Office API look here does not support Office 2016, or better said, any Framework over 2.0 I only found this slightly helpful comment by a user on this side, but they also suggest the Office API which doesn't work anymore.
I am very thankful for every helpful comment!
Upvotes: 1
Views: 634
Reputation: 49455
It doesn't matter which Office interop files are used (to which Office version they belong) - you can still automate Office applications from .Net applications. So, just add a COM reference (for Microsoft Office Outlook) to your application and use the following code:
using System;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace FileOrganizer
{
class Program
{
private void CreateMailItem()
{
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "This is the subject";
mailItem.To = "[email protected]";
mailItem.Body = "This is the message.";
mailItem.Display(false);
}
}
}
Upvotes: 1