auto purge after imap/pop3 send/receive

L

lbouchard

Hi,

I would like to write a macro to do an automatic purge of the curren
inbox folder after a send/receive to/from the imap or pop3 server.

is that possible, any code sample I could easily reuse?

Thank
 
E

Eric Legault [MVP - Outlook]

This sounds possible. The SyncObjects collection contains your defined
Send/Receive groups, and SyncObject exposes a SyncEnd event that has the
perfect spot to fire code to purge the current folder's contents.

This code will get you the appropriate SyncObject (make sure to include Dim
WithEvents objSO As Outlook.SyncObject in the module)

Sub GetSyncObject()
Dim objNS As Outlook.NameSpace
Dim objSOs As Outlook.SyncObjects

Set objNS = Application.GetNamespace("MAPI")
Set objSOs = objNS.SyncObjects
Set objSO = objSOs.Item("mvps.org")
End Sub

Private Sub objSO_SyncEnd()
Dim objCB As Office.CommandBarButton

'Get the Purge Deleted Items commandbar button
Set objCB = Application.ActiveExplorer.CommandBars.FindControl(, "5583")
objCB.Execute 'PURGE THE FOLDER
'WHAT HAPPENS IF THIS ISN'T AN IMAP FOLDER? <shrug>
End Sub

You'll have to test it and tweak it, but this *should* work. You'll have to
run GetSyncObject when Outlook starts in order to always have access to the
objSO_SyncEnd event, add garbage collection, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top