如何使用C ++ / COM获取用户在Outlook中以编程方式选择的电子邮件项目 [英] How to get an email item programatically selected by user in outlook using C++/COM
问题描述
我使用以下链接为插件创建了一个项目。
https://msdn.microsoft.com/en-us/library/office/ee941475%28v=office.14%29.aspx ?f = 255& MSPPError = -2147217396#BuildingNativeAddinforOL2010_CreatingaNativeAddin
我的要求是通过点击addins选项卡中的按钮来获取用户选择的电子邮件并将该输入发送到另一个dll。我已经使用上面的共享链接在outlook中创建了一个插件选项卡和按钮。我们是一个文档存储管理,因此用户可以从outlook / word / excel保存数据。
谢谢,
Vijay
我的尝试:
我是com的新手接口,所以我跟着上面链接中共享的内容。
我对c#的加载项有一点经验,但我相信你会理解概念。
我相信你应该使用带有COM的Microsoft.Office.Interop类来创建它。
查找当前选中的Microsoft .Office.Interop.Outlook.MailItem你可以用这个:
Outlook.MailItem Email = 空跨度>;
Outlook.Inspector actInspector = Outlook.Application.ActiveInspector();
if (actInspector == null )
{
Outlook。 Explorer explorer = Outlook.Application.ActiveExplorer();
尝试
{
Email = explorer.GetType()。InvokeMember( ActiveInlineResponse,System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags。 Public, null ,资源管理器, null ) as Outlook.MailItem;
}
最后
{
Marshal.ReleaseComObject(explorer);
}
}
else
{
try
{
Email = actInspector.CurrentItem as Outlook.MailItem;
}
最后
{
if (actInspector != null )Marshal.ReleaseComObject(actInspector);
}
}
来自
http://stackoverflow.com/questions/40973773/how-to-reliably-know-what-object-is-current-in-focus-outlook-window-ie-an-e/40979666# 40979666
要获得资源管理器中的所有MailItem选择,您可以使用:
< pre lang =c#> Outlook.Explorer explorer = null ;
Outlook.Selection selection = null ;
尝试
{
explorer = Global.OutlookApp.ActiveExplorer();
selection = explorer.Selection;
// selection.Count; - 示例
foreach (MailItem项 选项)
{
// item.Subject - 示例
}
}
最后
{
如果(选择!= null )
Marshal.ReleaseCOMObject(selection);
if (explorer!= null )
Marshal.ReleaseCOMObject (资源管理器);
}
I created a project for addins using following link.
https://msdn.microsoft.com/en-us/library/office/ee941475%28v=office.14%29.aspx?f=255&MSPPError=-2147217396#BuildingNativeAddinforOL2010_CreatingaNativeAddin
My requirement is to get the emails selected by user on click of a button from addins tab and send that input to another dll. And i already created a addins tab and buttons in outlook using above shared link. Ours is a document storage management so users can be able to save the data from the outlook/word/excel.
Thanks,
Vijay
What I have tried:
I am new to the com interfaces, so i followed same that was shared in above link.
I have a little experience in add-ins with c#, but I believe that you will understand the concept.
I believe that you should use Microsoft.Office.Interop classes with COM to create it.
To find the current selected Microsoft.Office.Interop.Outlook.MailItem you can use this:
Outlook.MailItem Email = null; Outlook.Inspector actInspector = Outlook.Application.ActiveInspector(); if (actInspector == null) { Outlook.Explorer explorer = Outlook.Application.ActiveExplorer(); try { Email = explorer.GetType().InvokeMember("ActiveInlineResponse", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null, explorer, null) as Outlook.MailItem; } finally { Marshal.ReleaseComObject(explorer); } } else { try { Email = actInspector.CurrentItem as Outlook.MailItem; } finally { if (actInspector != null) Marshal.ReleaseComObject(actInspector); } }
this came from
http://stackoverflow.com/questions/40973773/how-to-reliably-know-what-object-is-current-in-focus-outlook-window-i-e-an-e/40979666#40979666
To get all MailItem selectes in explorer you can use this:
Outlook.Explorer explorer = null; Outlook.Selection selection = null; try { explorer = Global.OutlookApp.ActiveExplorer(); selection = explorer.Selection; //selection.Count; --Example foreach (MailItem item in selection) { //item.Subject -- Example } } finally { if (selection != null) Marshal.ReleaseCOMObject(selection); if (explorer != null) Marshal.ReleaseCOMObject(explorer); }
这篇关于如何使用C ++ / COM获取用户在Outlook中以编程方式选择的电子邮件项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!