从我的WPF应用程序中,我创建并显示MailItem
,如下所示:
using Microsoft.Office.Interop.Outlook;
Application outlook = new Application();
NameSpace ns = outlook.GetNamespace("MAPI");
MailItem mailItem = outlook.CreateItem(OlItemType.olMailItem);
mailItem.Display(false);
string lastEntryId = mailItem.EntryID; // remember EntryId
用户现在可以撰写和发送邮件。
用户确实发送完邮件后,他在我的应用程序中确认发送。然后,我的应用程序应将邮件保存在文件系统中。我的方法是在发送后“记住” MailItem.EntryID
以使用它。
// ... lastEntryId is null therefore this code doesn't work
MailItem mailItem = ns.GetItemFromID(lastEntryId);
string fileName = GetValidFileName(item.Subject) + ".msg";
string file = Path.Combine(GetSaveDirectory(), fileName);
item.SaveAs(file);
但是lastEntryId
是发送前的null
,因此我无法使用它。
问题是:邮件项发送后如何访问?
即使您在发送邮件之前就拥有条目ID,发送邮件并将其移至“已发送邮件”文件夹时,它也会更改。仅在PST商店下保持不变。
已发送邮件文件夹中最早的Items.ItemAdd事件是您可以访问已发送邮件的地方。
如果您不在乎消息是否处于发送状态,也可以使用Application.ItemSend事件。