views:

11

answers:

1

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);
A: 

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.

Erv Walter