I have a Outlook Add-In from which I want to access Outbox of mail item and get the first mail of outbox programmatically in C# Visual Studio.
1 Answers
You can use the GetDefaultFolder method of the Store class. 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.
Sub ChangeCurrentFolder()
Dim myNamespace As Outlook.NameSpace
Set myNamespace = Application.GetNamespace("MAPI")
Set Application.ActiveExplorer.CurrentFolder = _
myNamespace.GetDefaultFolder(olFolderOutbox)
End Sub
Use the GetFirst method of the Items class to get the first object in the collection. Returns Nothing if no first object exists, for example, if there are no objects in the collection. To ensure correct operation of the GetFirst, GetLast, GetNext, and GetPrevious methods in a large collection, call GetFirst before calling GetNext on that collection and call GetLast before calling GetPrevious. To ensure that you are always making the calls on the same collection, create an explicit variable that refers to that collection before entering the loop.
You may find the How To: Get any standard / default folder in Outlook article helpful.