c# - Opening a new Outlook 2016 window with c#
问题描述
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!
解决方案
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 = "someone@example.com";
mailItem.Body = "This is the message.";
mailItem.Display(false);
}
}
}
推荐阅读
- node.js - Nodejs,TLS,只允许某些客户端证书
- python - 如何在 asyncio 中安排任务使其在特定日期运行?
- vba - 如何格式化选定的文本?
- php - 通过 xAMPP/MAMP 将 PHP 连接到 mySQL 数据库
- laravel - laravel flash 消息在异常中不起作用
- asp.net - 在 ASP.NET Core 中为 ControllerModel 注册操作
- python - 使用python从JSON解析值
- docker - 我应该如何在 ECS 上设置 Traefik?
- jetbrains-ide - 退出时切换到 youtrack 中的深色主题
- html - 为什么我的 iPhone 上的菱形标志看起来很奇怪?