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

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

  1. paulCC macrumors member

    Nov 2, 2012
    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. prisstratton macrumors 6502a


    Dec 20, 2011
    Winnipeg, Manitoba, Canada
    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:

    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………………
    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. hdas202 macrumors newbie

    Jun 4, 2013
    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
  4. BenB0632 macrumors newbie


    Jun 20, 2018
    Hey everybody - after lurking for months / years I have finally signed up!

    As my first post, I'm at the end of the road with regards extracting information via Applescript from Mail.

    In short, I want to extract:

    The Sender
    The Title
    The Message Body

    Date and time not important.

    all into a lovely MS Excel spreadsheet.

    Is there a script that I can utilise - the ones I have found concentrate on the Sender and/or title.

    Any assistance greatly appreciated.

Share This Page

3 April 2, 2013