Reputation: 315
I am writing a add-in for outlook 2010 (windows desktop version) using Visual studio tools for office. The outlook client has a exchange email configured. I want to allow the user to delete messages from the exchange server. I think it should be do-able if I use the exchange web services or use some third party library but in order to do this I would have to ask the user to re-specify his exchange email configuration to my add-in - I want to AVOID this.
I am wondering if there is a easier way to do this by calling some outlook or VSTO API, basically I am looking for a way to tell outlook to delete these messages from the server from my add-in's code. I have tried searching the VSTO documentation but have gotten no results.
Upvotes: 0
Views: 293
Reputation: 49455
It is not clear whether you have the cached mode enabled for the Exchange profile or not... But you can use the Delete method of Outlook items. The Delete
method deletes a single item in a collection. Note, the Delete method moves the item from the containing folder to the Deleted Items folder. If the containing folder is the Deleted Items folder, the Delete method removes the item permanently.
If you have the cached mode enabled in Outlook you need also to sync with the server to erase the item there too. The SyncObject.Start method begins synchronizing a user's folders using the specified Send\Receive group. For example, a VBA macro illustrates that:
Public Sub Sync()
Dim nsp As Outlook.NameSpace
Dim sycs As Outlook.SyncObjects
Dim syc As Outlook.SyncObject
Dim i As Integer
Dim strPrompt As Integer
Set nsp = Application.GetNamespace("MAPI")
Set sycs = nsp.SyncObjects
For i = 1 To sycs.Count
Set syc = sycs.Item(i)
strPrompt = MsgBox( _
"Do you wish to synchronize " & syc.Name &"?", vbYesNo)
If strPrompt = vbYes Then
syc.Start
End If
Next
End Sub
Upvotes: 0