IMAP tool to export list of emails to Excel/CSV ?

Discussion in 'Mac Applications and Mac App Store' started by paulCC, Apr 2, 2013.

  1. macrumors member

    Joined:
    Nov 2, 2012
    #1
    I know this is not exactly an Mac-app question, but I do work on a Macbook, and these forums are full of knowledgable people.....

    I have collected too many emails in Gmail, and would like to clean it up. I have deleted most of the emails form the various companies I purchased from over the years, but there is still some 25000 messages. ( which I believe is a wrong count, since a recent POP3 backup created 60000 messages..... ).

    What I am looking for is an IMAP tool or email client, which allows the info on email headers/subjects/addresses to be exported to CSV, XML or Excel files, so I can look for the remaining "clutterers" in my Gmail - sort by the "From" address, create a histogram, etc.

    Thanks for any info. PaulCC
     
  2. macrumors 6502

    prisstratton

    Joined:
    Dec 20, 2011
    Location:
    Winnipeg
    #2
    The AppleScript below should do what you want. Copy and paste the code into your AppleScript Editor and hit Run. It will export all the emails from the account you specify (using the From and Subject fields) directly into an Excel spreadsheet. You will need to modify line 11 (mailbox/account) to reflect your account settings. I ran the script on a couple of different mailboxes on my system and it worked fine. It does assume that you have MS-Excel installed on your system.

    I cannot claim this code, I found it here:

    https://discussions.apple.com/thread/2357203?start=0&tstart=0

    I did modify line 11, but I am no expert at this (just learning), so if you want something a little more fancy, others may need to jump in and help.

    tell application "Microsoft Excel"
    set theSpamFile to make new workbook
    set theSheet to active sheet of theSpamFile
    set formula of range "B1" of theSheet to "Subject"
    set formula of range "A1" of theSheet to "From"
    end tell
    tell application "Mail"
    set theRow to 2
    get mailboxes
    # change the next line to reflect your settings……….….here………………and...here
    set theMessages to every message in the mailbox "INBOX" of account "Gmail"
    repeat with aMessage in theMessages
    my SetFrom(sender of aMessage, theRow, theSheet)
    my SetSubject(subject of aMessage, theRow, theSheet)
    set theRow to theRow + 1
    end repeat
    end tell

    on SetFrom(theSender, theRow, theSheet)
    tell application "Microsoft Excel"
    set theRange to "A" & theRow
    set formula of (range theRange) of theSheet to theSender
    end tell
    end SetFrom

    on SetSubject(theSubject, theRow, theSheet)
    tell application "Microsoft Excel"
    set theRange to "B" & theRow
    set formula of range theRange of theSheet to theSubject
    end tell
    end SetSubject
     
  3. macrumors newbie

    Joined:
    Jun 4, 2013
    #3
    Export Gmail messages to CSV

    You can do this without using any 3rd party software. Simply using Google Docs.

    I have created a Google Script which will do the task for you. I have created 4 versions of the script. You can even export attachments to Excel.

    Just visit Export Gmail Messages to Excel or CSV
     

Share This Page