来自打开窗口的 c# VSTO Outlook 电子邮件正文 [英] c# VSTO Outlook email body from opened window
问题描述
我的 Outlook 的 VSTO 应用程序有问题.我想从选定的电子邮件中处理电子邮件正文.对于默认"列表之外的选定电子邮件,此代码工作正常:
I've a problem with my VSTO application for Outlook. I want to process the email body from a selected e-mail. For selected e-mails out of the "default" list this code works fine:
Object selItem = Globals.ThisAddIn.Application.ActiveExplorer().Selection[1];
Outlook.MailItem mailItem = (Outlook.MailItem)selItem;
return mailItem.Body;
但如果用户双击打开列表中的电子邮件,该电子邮件将显示在新窗口中.如果在此窗口中(在功能区上)执行加载项,则仍会使用列表中的电子邮件(现在在后台).
But if a user opens an email from the list with a double click, the email is displayed in a new window. If the addin is executed in this window (over the ribbon), the email from the list is still used (which is now in the background).
有没有办法找出插件是否在单独的窗口中启动,然后从中获取电子邮件正文?
Is there a way to find out if the plugin was started in a separate window and then get the email body from it?
问候,弗洛里安
推荐答案
巧合的是,我刚刚处理了类似的事情.我的情况并不相同,但因为我可以轻松拼凑出您正在寻找的内容,请参见下文.我还没有测试过这个,显然你必须处理将正确的引用传递给你的 Outlook 应用程序,但因为我可以立即使用它,我认为它会传递它并希望你会发现它有帮助.
Coincidentally, I just dealt with something similar to this. My situation isn't identical, but since I could easily piece together what it seems like you're looking for see below. I haven't tested this, and obviously you'll have to handle passing the correct reference to your Outlook Application, but since i had this immediately available I figured it would pass it along with the hope that you'll find it helpful.
private static void ribbonButton_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application application = new Outlook.Application();
Outlook.Inspector inspector = application.ActiveInspector();
if (application.ActiveExplorer().Selection[1] is Outlook.MailItem explorerMailItem)
{
// Write code to handle message if sourced from explorer (i.e., Reading Pane)
}
else if (inspector.CurrentItem is Outlook.MailItem inspectorMailItem)
{
// Write code to hanlde message if sourced from inspector
// (i.e., openened (double-clicked) message
}
}
这篇关于来自打开窗口的 c# VSTO Outlook 电子邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!