我仍然在編程領域。但是現在我遇到了一個小問題。我目前正在開發一個 Outlook 插件,它接收電子郵件并將其作為附件打包到新郵件中,并自動將其發送到特定地址。到目前為止效果很好。但是,只有在我在新視窗中打開要作為附件發送的郵件時,它才有效。
然而,我的目標是,如果郵件在閱讀區打開就已經足夠了。但是,不幸的是,我還沒有找到解決這個問題的方法。也許有人可以給我一個鏈接或示例來處理郵件,該郵件當前顯示在 Visual Studio 的預覽中。作為一種語言,我使用 C#。
到目前為止,我到達打開的郵件如下:
String path = "C:\\Test\\Mail.msg";
Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
MailItem mailitem = inspector.CurrentItem as MailItem
但是如何到達可以在閱讀區預覽的郵件呢?
非常感謝您的幫助。
uj5u.com熱心網友回復:
要從 Outlook 的資源管理器視窗中獲取當前選定的專案,您需要使用以下代碼:
if (Application.ActiveExplorer().Selection.Count > 0)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem =
(selObject as Outlook.MailItem);
itemMessage = "The item is an e-mail message."
" The subject is " mailItem.Subject ".";
mailItem.Display(false);
}
else if (selObject is Outlook.ContactItem)
{
Outlook.ContactItem contactItem =
(selObject as Outlook.ContactItem);
itemMessage = "The item is a contact."
" The full name is " contactItem.Subject ".";
contactItem.Display(false);
}
else if (selObject is Outlook.AppointmentItem)
{
Outlook.AppointmentItem apptItem =
(selObject as Outlook.AppointmentItem);
itemMessage = "The item is an appointment."
" The subject is " apptItem.Subject ".";
}
else if (selObject is Outlook.TaskItem)
{
Outlook.TaskItem taskItem =
(selObject as Outlook.TaskItem);
itemMessage = "The item is a task. The body is "
taskItem.Body ".";
}
else if (selObject is Outlook.MeetingItem)
{
Outlook.MeetingItem meetingItem =
(selObject as Outlook.MeetingItem);
itemMessage = "The item is a meeting item. "
"The subject is " meetingItem.Subject ".";
}
}
但是,如果您需要在 Explorer 視圖中獲取所有選定的專案,則需要遍歷Selection物件中的所有專案。
uj5u.com熱心網友回復:
使用Application.ActiveExplorer.Selectioncollection 回圈遍歷選定的訊息并適當地處理它們。
請記住,(只是喜歡Application.ActiveInspector),你可以有比其他專案MailItem,例如ContactItem,AppointmentItem,ReportItem等你需要這樣的處理專案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/359927.html
下一篇:如何為電子郵件簽名優化此代碼?
