简体   繁体   English

MailItem 发送后如何访问它?

[英]How can I access a MailItem after it has been sent?

From my WPF app I create and display a MailItem like following:从我的 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

The user can now compose and send the mail.用户现在可以撰写和发送邮件。

After the user did send the mail he confirms the sending in my app.用户发送邮件后,他在我的应用程序中确认发送。 My app then should save the mail in file system.然后我的应用程序应该将邮件保存在文件系统中。 My approach was to "remember" the MailItem.EntryID to use it after sending.我的方法是“记住” 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);

But lastEntryId is null before sending therefore I cannot use it.但是在发送之前lastEntryIdnull因此我不能使用它。

Question is: how can I access the MailItem after it has been sent?问题是:发送后如何访问 MailItem?

Even if you had the entry id before the message was sent, it would change when the message is sent and moved to the Sent Items folder.即使您在发送消息之前拥有条目 ID,但在发送消息并移动到“已发送邮件”文件夹时它也会更改。 It stays the same only under the PST store.它仅在 PST 商店下保持不变。

Items.ItemAdd event on the Sent Items folder is the earliest you can access the sent message.已发送邮件文件夹上的 Items.ItemAdd 事件是您最早可以访问已发送邮件的事件。

You can also use Application.ItemSend event if you don't care whether the message is in the sent state or not.如果您不关心消息是否在发送的 state 中,您也可以使用 Application.ItemSend 事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM