如何创建“日志文件”来自 Outlook 插件的“已删除邮件”文件夹中的消息

发布于 2024-09-15 23:58:47 字数 725 浏览 7 评论 0原文

我有一个插件可以将联系人文件夹与外部源同步。同步每天都会发生(或根据需要手动进行),并且需要一段时间。用户要求插件提供有关同步的信息,以便他们知道同步已成功完成等。

由于 Outlook API 不提供向状态栏添加信息的方法(即有关同步发生的详细信息) ,我想每次同步时自动创建一个日志文件(并将其粘贴在“已删除邮件”文件夹中,以免妨碍)。

当我尝试创建一条消息并将其 .Move() 到已删除的项目文件夹时,它出现在那里,但没有接收时间,因此被排序到列表的末尾并且很难找到。此外,它对用户来说就像一条未发送的消息(草稿)。

有没有办法创建消息并将接收时间设置为大约创建消息的时间(该属性是只读的)?

NameSpace mapi = _outlook.GetNamespace("MAPI");
MAPIFolder deletedItems = mapi.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
MailItem message = (MailItem)_outlook.CreateItem(OlItemType.olMailItem);
message.Subject = "Contact Sync Errors";
message.BodyFormat = OlBodyFormat.olFormatPlain;
message.Body = "This is my log message";
message.Move(deletedItems);

I have an addin that synchronized the contacts folder with an outside source. The Sync happens daily (or manually on demand) and takes a while. Users have asked for the addin to provide information about the sync so that they know it completed successfully, etc.

Since the Outlook API doesn't provide a way to add information to the status bar (i.e. details about the sync as it is happening), I would like to create a log file automatically each sync (and stick it in the Deleted Items folder so that it is out of the way).

When I tried to create a message and .Move() it to the deleted items folder, it appeared there, but without a Received time and so was sorted to the end of the list and hard to find. Also, it looks to the user like an unsent message (a draft).

Is there a way to create a message and have the Received time be set to approx the time the message was created (the property is read-only)?

NameSpace mapi = _outlook.GetNamespace("MAPI");
MAPIFolder deletedItems = mapi.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
MailItem message = (MailItem)_outlook.CreateItem(OlItemType.olMailItem);
message.Subject = "Contact Sync Errors";
message.BodyFormat = OlBodyFormat.olFormatPlain;
message.Body = "This is my log message";
message.Move(deletedItems);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

也只是曾经 2024-09-22 23:58:47

这就是我最终所做的。我使用帖子而不是消息,因为这样效果更好。

PostItem message = (PostItem)this.Application.CreateItem(OlItemType.olPostItem);
message.Subject = "Contact Sync Log";
message.BodyFormat = OlBodyFormat.olFormatPlain;
message.Body = "My Message Here";
message.Post();
message.Delete();

创建帖子,填写详细信息,“发布”,以便它具有有效的时间戳,然后立即删除(因为我希望将其放在“已删除邮件”文件夹中)。如果我没有删除它,它就会在“收件箱”文件夹中。

This is what I ended up doing. I used a Post instead of a Message because that worked better.

PostItem message = (PostItem)this.Application.CreateItem(OlItemType.olPostItem);
message.Subject = "Contact Sync Log";
message.BodyFormat = OlBodyFormat.olFormatPlain;
message.Body = "My Message Here";
message.Post();
message.Delete();

The Post is created, filled out with details, "Posted" so that it has valid timestamps, and then immediately deleted (because I wanted it in the Deleted Items folder). Had I not deleted it, it would have been in the Inbox folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文