Unable to delete items from gmail IMAP Trash using Outlook 2010

Status
Not open for further replies.

UncleBill

Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Sincerest apologies if I'm re-treading old ground.....I've really, really made an effort to review existing posts.
I'm using Outlook 2010. I have multiple POP3 yahoo accounts and multiple IMAP gmail accounts.
I've written (portions blatantly plagiarized) a VBA macro that I intend to manually invoke. It scans all accounts looking for 'Sent Items', 'Sent Mail', and 'Junk E-mail' folders, deleting items 7 days or older.
My Outlook accounts are configured to move items to the 'Deleted Items" or 'Trash' folders when an item is deleted.
This macro functionality works as expected.
The macro then scans the items in the 'Deleted Items' and 'Trash' folders, deleting items 14 days or older. Although this produces no error, the items selected in the IMAP 'Trash' folders are not deleted. At macro end, they still reside in the 'Trash' folder.
What additional must I do to force the delete?
My admittedly rookie code follows: (helpful critiquing welcome)
'**************************************************************************************************
'Description:
' This VBA Script iterates thru all accounts, all folders.
' If the folder meets the selection criteria, then its items => 7 days old are deleted.
' The Trash (IMAP) and Deleted Items (POP3) folders are then processed, deleting items => 14 days old.
'**************************************************************************************************
Const DAYS_OLD = 7

Sub Iterate_Accounts_Delete_Folder_Contents()
IterateAccountsDeleteFolderContents
End Sub

Private Sub IterateAccountsDeleteFolderContents()
On Error GoTo On_Error
Dim objNS As NameSpace
Dim objAccount As Outlook.account
Dim objFolders As Outlook.Folders
Dim objFolder As Outlook.folder
Dim subFolder As Outlook.folder

Dim objFoldersToProcess As Outlook.Folders
Dim objItemsToProcess As Outlook.Items
Dim i As Long

Set objNS = Application.GetNamespace("MAPI")
Set objFolders = objNS.Folders
For Each objFolder In objFolders
Set objAccount = GetAccountForFolder(objFolder)

DisplayAccountNameAndType objAccount

For Each subFolder In objFolder.Folders
If (subFolder.Name = "Sent Items") Or (subFolder.Name = "Sent Mail") Or (subFolder.Name = "Junk E-mail") Then
Debug.Print " Folder selected for processing = " + subFolder.Name
Set objItemsToProcess = subFolder.Items
For i = objItemsToProcess.Count To 1 Step -1
If Date - objItemsToProcess.Item(i).ReceivedTime >= DAYS_OLD Then
Debug.Print " Item being deleted = " + objItemsToProcess.Item(i) + " : " + Str(objItemsToProcess.Item(i).ReceivedTime)
objItemsToProcess.Item(i).Delete
End If
Next
Set objFoldersToProcess = subFolder.Folders
For i = objFoldersToProcess.Count To 1 Step -1
If Date - objFoldersToProcess.Item(i).ReceivedTime >= DAYS_OLD Then
Debug.Print " Folder being deleted = " + objFoldersToProcess.Item(i).Name + " : " + Str(objFoldersToProcess.Item(i).ReceivedTime)
objFoldersToProcess.Item(i).Delete
End If
Next
End If
Next

For Each subFolder In objFolder.Folders
If (subFolder.Name = "Trash") Or (subFolder.Name = "Deleted Items") Then
Debug.Print " Folder selected for processing = " + subFolder.Name
Set objItemsToProcess = subFolder.Items
For i = objItemsToProcess.Count To 1 Step -1
If Date - objItemsToProcess.Item(i).ReceivedTime >= (2 * DAYS_OLD) Then
Debug.Print " Item being deleted = " + objItemsToProcess.Item(i) + " : " + Str(objItemsToProcess.Item(i).ReceivedTime)
objItemsToProcess.Item(i).Delete
End If
Next
Set objFoldersToProcess = subFolder.Folders
For i = objFoldersToProcess.Count To 1 Step -1
If Date - objFoldersToProcess.Item(i).ReceivedTime >= (2 * DAYS_OLD) Then
Debug.Print " Folder being deleted = " + objFoldersToProcess.Item(i).Name + " : " + Str(objFoldersToProcess.Item(i).ReceivedTime)
objFoldersToProcess.Item(i).Delete
End If
Next
End If
Next

Next
Set objNS = Nothing
Set objAccount = Nothing


Exiting:
Exit Sub


On_Error:
MsgBox "error=" & Err.Number & " " & Err.Description
Resume Exiting
End Sub

Private Function GetAccountForFolder(objFolder As Outlook.folder) As Outlook.account
Dim objStoreID As String
objStoreID = objFolder.StoreID

'Enumerate the accounts defined for the session.
For Each account In Application.session.accounts
If account.DeliveryStore.StoreID = objStoreID Then
'Return the account whose default delivery StoreID matches the folder StoreID
Set GetAccountForFolder = account
Exit Function
End If
Next

'No account matches, so return Nothing.
Set GetAccountForFolder = Nothing
End Function

Private Sub DisplayAccountNameAndType(ByVal objAccount As Outlook.account)
Debug.Print ("")
Debug.Print objAccount.DisplayName

If (objAccount.AccountType = Outlook.OlAccountType.olImap) Then
Debug.Print "Account Type = IMAP"
ElseIf (objAccount.AccountType = Outlook.OlAccountType.olPop3) Then
Debug.Print "Account Type = POP3"
Else
Debug.Print "Account Type = UNKNOWN"
End If
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange

UncleBill

Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
I'm assuming the pop3 folders delete correctly, only the imap accounts don't? What at the gmail settings for deleted items?
https://mail.google.com/mail/u/0/?pli=1#settings/fwdandpop - i don't know which is the best configuration for your configuration.

Thanks for the reply. Here's a screen shot of the gmail settings page.
Gmal Settings.jpg
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Try changing the 'when a message is marked as deleted from last visible folder' to move to trash and see if it works as desired.
 

UncleBill

Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Try changing the 'when a message is marked as deleted from last visible folder' to move to trash and see if it works as desired.
Dianne,
The options under When a message is marked as deleted and expunged from the last visible IMAP folder: were disabled until I change When I mark a message in IMAP as deleted:
from

Auto-Expunge on - Immediately update the server. (default)
to
Auto-Expunge off - Wait for the client to update the server.

After making these 2 changes, the problem persists.
 

UncleBill

Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Dianne,
The options under When a message is marked as deleted and expunged from the last visible IMAP folder: were disabled until I change When I mark a message in IMAP as deleted:
from
Auto-Expunge on - Immediately update the server. (default)
to
Auto-Expunge off - Wait for the client to update the server.

After making these 2 changes, the problem persists.

One thing to be aware of......when using the gui to delete either a POP3 Deleted Item or a IMAP Trash item, both prompt for verification that I want to permanently delete the item. Clicking Yes deletes the item from both POP3 Deleted Item or IMAP Trash.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
V Unable to delete from deleted items folder due to error message Using Outlook 3
G Outlook calendar entry corrupted. Constant pop up when you open outlook. Unable to delete or remove. Using Outlook 2
F Outlook 2010 unable to delete emails from scanner Using Outlook 1
P Unable to delete custom forms in outlook 2010 Using Outlook 1
M Unable to delete multiple calendars (from multiple accounts); only want ONE. Using Outlook 2
H Message in outbox but never is sent and unable to delete because it's in the process of sending already. Using Outlook 3
N Error: 8004102A - Unable to delete emails properly Using Outlook 1
T unable to move or delete emails in IMAP folder Using Outlook 2
C RE: unable to delete large message clogging outbox Using Outlook 3
L Unable to Sync Web/Android MS To Do with Windows Outlook Tasks Using Outlook 3
A Unable to save recurring Meeting to Documents folder due to error Using Outlook 2
O Outlook 365 - suddenly unable to send using Gmail POP3 Using Outlook 10
S Outlook 2010 unable to change default font Using Outlook 7
Q Unable to Sync Quicken reminder with Outlook 2016 64Bit Using Outlook 1
S Unable to remove rule outlook 2010 Using Outlook 0
L Wierd Office 365 Contact unable to edit body of random contacts Using Outlook 5
X Unable to send an email from one account to another on same PC Using Outlook 2
Mark Foley Unable to subscribe to published calendar in Outlook 2010 Using Outlook 4
S Unable to Edit Contact Information in Certain Contact Folders Using Outlook 3
P Deleted Items - Unable to Iterate All of Items Outlook VBA and Custom Forms 1
G Unable to dismiss reminders from share point list calendar shared in Outlook Using Outlook 2
R Unable to install without email account Using Outlook 4
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
A Outlook 2016- unable to have all subfolders expanded when opening outlook Using Outlook 11
avant-guvnor Unable to view certain emails in Outlook 2016 Using Outlook 16
M Unable to Configure Gmail Account in Outlook 2007 Using Outlook 1
D Unable to Send On Behalf of Another User Exchange Server Administration 0
J Unable to link email messages in BCM using a single microsoft office 365 account in outlook 2013 BCM (Business Contact Manager) 1
Tim King Outlook 365 unable to change accounts Using Outlook 0
R Unable to send mail using Cox.net Using Outlook 1
T Unable to 'Upload a file' using popup 'Browse' button Using Outlook 0
D Unable to add email address to contact Using Outlook 3
O OL2000: Unable to create IMAP account Using Outlook 2
wallisellener Unable to reply/post/create new thread using Chrome BCM (Business Contact Manager) 5
Rupert Dragwater unable to change font sizes in some replies Using Outlook 3
C Unable to see meeting attendees Outlook 2010 Using Outlook 5
M Unable to email from Word or Excel Using Outlook 11
O Unable to check name. Using Outlook 3
T Unable to create contacts subfolder in EAS profile Using Outlook.com accounts in Outlook 6
B Unable to search delegated mailfile Using Outlook 3
K Unable to activate QueryBuilder in Outlook 2010 (32bit) with Windows 7 (64bit) Using Outlook 1
C Unable to forward email with URL Using Outlook 2
R New computer, OL2010 unable to display shared calendar appointments Exchange Server Administration 3
S unable to send email from my second address (outlook 2007) Using Outlook 2
A "Unable to display the folder" error when accessing Group mailbox Using Outlook 0
C Outlook 2010, two exchange mailboxes configured.Unable to see 2ndrymeeting req Using Outlook 2
H Outlook 2010 unable to send iCloud account e-mail after iOS 7 upgrade Using Outlook 12
B Unable to apply rule on Exchange server functional account Exchange Server Administration 1
J Archives: Unable to locate emails Using Outlook 1
S Unable to send or reeceive email in new Exchange 2010 Exchange Server Administration 0

Similar threads

Top