none
How to access and change AutoArchive Options for IMAP folders? RRS feed

  • Question

  • Hello,

    I'm pulling my hairs. There is quite a nice VBA script to set AutoArchive Options in Outlook (2007) recursively on a hierachy of folders:

    However it does not work in IMAP folders. The reason is, that the call to

    • oFolder.GetStorage(   "IPC.MS.Outlook.AgingProperties", olIdentifyByMessageClass)

    is not supported for IMAP folders.

    However I have not found any other way to access auto archiving options.

    Any ideas how this could be done for IMAP?

    Thank you for your help

    Wallenstein

    Friday, April 17, 2015 10:49 AM

Answers

  • Wallenstein,

    Still my question is: Is it possible to programmatically set auto-archive(aging settings for IMAP folders?

    No, it is not. You can develop a VBA macro with a similar functionality or set up such settings on the server-side. Outlook is just a client application synchronized with the IMAP server. 

    Monday, April 20, 2015 10:56 AM
  • Hi Wallenstein,

    As Eugene said that you can develop a VBA macro for moving/deleting mail items programmatically.

    The simple code to move mail items:

    Sub Archive_Outlook_eMails_To_Backup_PST_Folder()
        ' Declare Objects
        Dim SourceFolder As Outlook.MAPIFolder, DestFolder As Outlook.MAPIFolder
        Dim MailItem As Outlook.MailItem
        Dim SourceMailBoxName As String, DestMailBoxName As String
        Dim Source_Pst_Folder_Name As String, Dest_Pst_Folder_Name  As String
        Dim MailsCount As Double, NumberOfDays As Double
        
        'Set Number of days for aging check
        NumberOfDays = 1
        
        'Source Mailbox or PST name
        SourceMailBoxName = "YourEmailAccount@gmail.com"
        Source_Pst_Folder_Name = "SourcePSTFolder"
        Set SourceFolder = Outlook.Session.Folders(SourceMailBoxName).Folders(Source_Pst_Folder_Name)
        
        'Backup to this Mailbox or PST name
        DestMailBoxName = "Archive Folders"
        Dest_Pst_Folder_Name = "Inbox"
        Set DestFolder = Outlook.Session.Folders(DestMailBoxName).Folders(Dest_Pst_Folder_Name)
        
        MailsCount = SourceFolder.Items.Count
        While MailsCount > 0
        
            'Backup Mails Older than "Number of Days"
            Set MailItem = SourceFolder.Items.Item(MailsCount)
            If VBA.DateValue(VBA.Now) - VBA.DateValue(MailItem.ReceivedTime) >= NumberOfDays Then
                SourceFolder.Items.Item(MailsCount).Move DestFolder
            End If
            
            MailsCount = MailsCount - 1
        Wend
     
        MsgBox "Mailes in " & Source_Pst_Folder_Name & " are Processed"
    End Sub
    
    

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 20, 2015 5:43 AM
    Moderator

All replies

  • Hello Wallenstein,

    The GetStorage method of the Folder class returns StorageItem object on the parent Folder to store data for an Outlook solution. GetStorage returns an error if the store type of the folder is not supported. The following stores return an error when GetStorage is called:

    • Hotmail store
    • Internet Message Access Protocol (IMAP) stores
    • Delegate stores
    • Public folder stores

    You need to develop a macro to move or delete Outlook items using the VBA code in that case.

    BTW In Outlook 2013 I have got an IMAP account configured and I am able to access the "IPC.MS.Outlook.AgingProperties" item.

    Friday, April 17, 2015 11:22 AM
  • Hello Eugene

    Thank you for your prompt answer.

    I have already reviewed the documentation for GetStorage(). Suprisingly even for Outlook 2013 the documentation claims, not to work for IMAP. So you seem to be lucky :-)

    However what do you mean by "You need to develop a macro to move or delete Outlook items using the VBA code in that case". I'm really expected do write the whole AutoArchive-Code myself again in VBA?

    My intention was, simply to avoid manually clicking through a deep hierachy of folders.

    Wallenstein

    Friday, April 17, 2015 11:34 AM
  • There is no need to click each folder manually. You can develop a VBA macro for moving/deleting mail items programmatically. See Getting Started with VBA in Outlook 2010 for more information.
    Friday, April 17, 2015 12:51 PM
  • Hi Wallenstein,

    As Eugene said that you can develop a VBA macro for moving/deleting mail items programmatically.

    The simple code to move mail items:

    Sub Archive_Outlook_eMails_To_Backup_PST_Folder()
        ' Declare Objects
        Dim SourceFolder As Outlook.MAPIFolder, DestFolder As Outlook.MAPIFolder
        Dim MailItem As Outlook.MailItem
        Dim SourceMailBoxName As String, DestMailBoxName As String
        Dim Source_Pst_Folder_Name As String, Dest_Pst_Folder_Name  As String
        Dim MailsCount As Double, NumberOfDays As Double
        
        'Set Number of days for aging check
        NumberOfDays = 1
        
        'Source Mailbox or PST name
        SourceMailBoxName = "YourEmailAccount@gmail.com"
        Source_Pst_Folder_Name = "SourcePSTFolder"
        Set SourceFolder = Outlook.Session.Folders(SourceMailBoxName).Folders(Source_Pst_Folder_Name)
        
        'Backup to this Mailbox or PST name
        DestMailBoxName = "Archive Folders"
        Dest_Pst_Folder_Name = "Inbox"
        Set DestFolder = Outlook.Session.Folders(DestMailBoxName).Folders(Dest_Pst_Folder_Name)
        
        MailsCount = SourceFolder.Items.Count
        While MailsCount > 0
        
            'Backup Mails Older than "Number of Days"
            Set MailItem = SourceFolder.Items.Item(MailsCount)
            If VBA.DateValue(VBA.Now) - VBA.DateValue(MailItem.ReceivedTime) >= NumberOfDays Then
                SourceFolder.Items.Item(MailsCount).Move DestFolder
            End If
            
            MailsCount = MailsCount - 1
        Wend
     
        MsgBox "Mailes in " & Source_Pst_Folder_Name & " are Processed"
    End Sub
    
    

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 20, 2015 5:43 AM
    Moderator
  • Hello Starain,

    Thank you very much for you elaborated answer.

    However, what the proposed code does, seems to be the standard archiving feature of Outlook (2007):

    •    File -> Archive -> archive this folder and all sub-folders

    So, no need to replace this functionality by a home crafted script :-)

    Still my question is: Is it possible to programmatically set auto-archive(aging settings for IMAP folders?

    The answer seems no.

    Thank you for your kind support

    Wallenstein


    Monday, April 20, 2015 6:30 AM
  • Wallenstein,

    Still my question is: Is it possible to programmatically set auto-archive(aging settings for IMAP folders?

    No, it is not. You can develop a VBA macro with a similar functionality or set up such settings on the server-side. Outlook is just a client application synchronized with the IMAP server. 

    Monday, April 20, 2015 10:56 AM
  • Hi,

    I am trying to move my inbox mails to PST through VBA using Macro which you have provided, But i have confused in couple of things.

    I have given my email id as Ex: someone@gmail.com

    I have given source_pst_Folder_Name as "Inbox"

     SourceMailBoxName = "YourEmailAccount@gmail.com"
        Source_Pst_Folder_Name = "SourcePSTFolder"

    At the same i cant able to run form below step, because Source folder not found

    Set SourceFolder = Outlook.Session.Folders(SourceMailBoxName).Folders(Source_Pst_Folder_Name)

    Could please check and help which i need to select as Source folder, destmailboxname and dest_pst_folder_Name

    Thank You for you're support

    Sunday, January 29, 2017 6:33 PM