Archiving attachments for a specified mailbox.

Posted on 2007-08-02
Last Modified: 2008-01-09
Recently I received a request to automatically archive attachments that come into a specific mailbox to a network directory. After the attachment has been archived the message that containined the attachment should be deleted.  I have attempted creating a VBscript to do this but have been unsuccessful in finding a resolution to this thus far. EMC's EmailXtender is also not capable of doing this. Does anyone out there know of a way to accomplish this? Thanks to all for taking the time to read through this question, hopefully there is an answer out there!

Question by:MitchV85
    LVL 28

    Expert Comment

    You can accomplish this with the built-in Auto-Archive feature in Outlook. Right-click Inbox for the mailbox in question and choose Properties. On the Auto-Achive (or similar) tab you find ia mulitude of settings. Select 0 days and select Move to the specified folder.
    LVL 76

    Expert Comment

    by:David Lee
    Hi, Mitch.

    I can do this with a simple bit of scripting.  The only question I have is what you mean when you say "archiving".  Are you expecting this to work via the archiving process?  If so, then that's not possible.  Or does archiving mean to run a an archiving like process?  If so, then that's easy.  

    LVL 76

    Expert Comment

    by:David Lee
    LVL 5

    Author Comment

    First PeakPeak, thank you for the reply however I do not want to have a PST file to which the messages are archived to.

    BlueDevilFan, when I had said archiving you are correct in that I was looking for an archive-like process. Something that will extract the attachments from the messages and move them to a specified network volume. After the attachment has been moved the message should be deleted. If you have a script that will perform this action I will petition to award you 2000 points. :)

    Thanks both for the replies!

    LVL 76

    Accepted Solution


    Here you go.  Follow these instructions to use this.

    1.  Start Outlook
    2.  Click Tools->Macro->Visual Basic Editor
    3.  If not already expanded, expand Modules and click on Module1 (if you expand the tree in the top left pane and don't see Module; right click on "Project 1" and choose "Insert Module", then hightlight "Module 1" so you can paste into it in the right hand pane)
    4.  Copy the code below and paste it into the right-hand pane of the VB Editor
    5.  Edit the code as needed.  I inserted a comment line immediately before each line that needs to be changed.
    6.  Click the diskette icon on the toolbar to save the changes
    7.  Close the VB Editor
    8.  Click Tools->Macro->Security
    9.  Change the Security Level setting to Medium
    10.  If the file system folder where attachments will be saved doesn't already exist, then create it.
    11.  Select an Outlook folder by clicking on it.
    12.  Run the macro.  It will prompt for a cutoff date when it launches.  All messages dated before the cutoff date will be processed by the macro.  All attachments will be saved into the designated file system folder and the source message deleted.  

    Sub RemoveAttachmentsBasedOnDate()
        Dim olkFolder As Outlook.MAPIFolder, _
            olkItem As Object, _
            olkAttachment As Outlook.Attachment, _
            strCutoff As String, _
            strTitle As String, _
            strAttachmentFolder As String, _
            intIndex As Integer
        'Change the folder path on the following line to the folder on your system where attachments will be saved
        strAttachmentFolder = "C:\eeTesting\MyAttachments\"
        strTitle = "Remove Attachments Based on Date"
        'Change the default date on the following line as needed
        strCutoff = InputBox("Enter a cutoff date.  Aattachments on all messages prior to that date will be saved and the source message deleted.", strTitle, Date - 30)
        If Not IsDate(strCutoff) Then
            MsgBox "You failed to enter a valid date.  The macro is aborting.", vbCritical + vbOKOnly, strTitle
            Exit Sub
        End If
        Set olkFolder = Application.ActiveExplorer.CurrentFolder
        For intIndex = olkFolder.Items.Count To 1 Step -1
            Set olkItem = olkFolder.Items.Item(intIndex)
            If olkItem.ReceivedTime < CDate(strCutoff & " 00:00:01 AM") Then
                If olkItem.Attachments.Count > 0 Then
                    For Each olkAttachment In olkItem.Attachments
                        olkAttachment.SaveAsFile strAttachmentFolder & olkAttachment.FileName
                End If
            End If
        Set olkAttachment = Nothing
        Set olkItem = Nothing
        Set olkFolder = Nothing
        MsgBox "All done!", vbInformation + vbOKOnly, strTitle
    End Sub
    LVL 5

    Author Comment

    $$$ Thanks BlueDevilFan, worked great!
    LVL 76

    Expert Comment

    by:David Lee
    You're welcome, Mitch.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Easy CSR creation in Exchange 2007,2010 and 2013
    Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
    In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
    In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now