Outlook 插件 ActiveExplorer 和带有附件的检查器 CurrentItem
Outlook Addin ActiveExplorer and inspector CurrentItem with Attachments
需要另一个视图,因为我迷路了。
在 outlook 中,有两种发送电子邮件的方法,新的 window 新电子邮件或消息预览。我需要一个检查两个发送选项的功能,以便用户不会忘记附加附件。
我在这里找到了这个很棒的代码
问题是函数总是说没有附加附件。
private void Btn_Check_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
Inspector inspector = application.ActiveInspector();
if (application.ActiveExplorer().Selection[1] is MailItem explorerMailItem)
{
if (explorerMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachments isnt here");
this.Hide();
}
else
{
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
} else if (inspector.CurrentItem is MailItem inspectorMailItem)
{
if (inspectorMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachment isnt here");
this.Hide();
} else {
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
}
}
首先,使用 Application.ActiveWindow
并将其转换为 Inspector
或 Explorer
以查看哪个 window 实际处于活动状态。
其次,在Explorer
的情况下,不要使用Explorer.Selection
,使用Explorer.ActiveInlineResponse
(returns null 或内联组合的新项目)。
需要另一个视图,因为我迷路了。
在 outlook 中,有两种发送电子邮件的方法,新的 window 新电子邮件或消息预览。我需要一个检查两个发送选项的功能,以便用户不会忘记附加附件。
我在这里找到了这个很棒的代码
问题是函数总是说没有附加附件。
private void Btn_Check_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
Inspector inspector = application.ActiveInspector();
if (application.ActiveExplorer().Selection[1] is MailItem explorerMailItem)
{
if (explorerMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachments isnt here");
this.Hide();
}
else
{
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
} else if (inspector.CurrentItem is MailItem inspectorMailItem)
{
if (inspectorMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachment isnt here");
this.Hide();
} else {
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
}
}
首先,使用 Application.ActiveWindow
并将其转换为 Inspector
或 Explorer
以查看哪个 window 实际处于活动状态。
其次,在Explorer
的情况下,不要使用Explorer.Selection
,使用Explorer.ActiveInlineResponse
(returns null 或内联组合的新项目)。