mma
mma

Reputation: 401

Getting the actual sender's "sent items" folder in Office 365 Outlook (c#)

My earlier problem about catching an email message just after it has sent was resolved by using the Items.ItemAdd event handler of the Sent Items folder. This works fine when I don't change the sender mailbox. But if I change it by selecting some other account from the dropdown list of the sender on the interface shown by mailItem.Display(true); , then the sent message lands in the "sent items" folder of this other account, but

Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);

doesn't change accordingly, so in this way I can't catch the message. How could I get the "sent items" folder of the selected (not default) sender? (an acceptable workaround would be to change the default mailbox, but I also don't know how to do this).

Upvotes: 0

Views: 679

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49405

The GetDefaultFolder method of the Store class returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

You can to handle the ItemSend event of the Application class where you can get the sender. Then you can find associated store and use the GetDefaultFolder method to get the correct Sent Items folder.

Be aware, the SaveSentMessageFolder property of the MailItem class returns or sets a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent (instead of the Sent Items folder).

Upvotes: 1

Related Questions