7 Replies Latest reply: Mar 11, 2010 4:33 PM by Barney-15E
SacMac Level 1 (95 points)
I'd like to export only emails from my Spam folder into a format I can then import into Excel. All I essentially need is the Subject and From fields. Does anyone know how I can do this?

MacBook Pro unibody, Mac OS X (10.6.2), MacBook, iMac, iPhone 3GS, iPods, AirPort Extreme and Apple TV
  • SacMac Level 1 (95 points)
    Gaging by the lack of responses over the last week I guess you can't do it.
  • elmac Level 5 (4,230 points)
    Hi, Open email, then -> File -> Save As (I save to desktop) when it is on the desktop Right click and select say TextEdit -> the email will open as a text doc with everything you need...L
  • SacMac Level 1 (95 points)
    I know how to save/export individual messages. What I'm trying to do is export ALL the messages out of a particular box without having to do so individually.
  • elmac Level 5 (4,230 points)
    Hi, try this link:-
    http://mac.softpedia.com/get/Utilities/Export-Messages.shtml
    ...L

    Message was edited by: elmac
  • CJLinst Level 1 (0 points)
    1. Select all messages with Cmd-A
    2. File -> Save As
    3. Choose a descriptive filename
    4. Save as Format: "Raw Message Source"

    You'll end up with a standard mbox file of all selected messages.

    Credit to: http://www.macosxhints.com/article.php?story=20060706201156481

    You could then write a perl script to walk through the mbox outputting the headers in CSV or whatever.
  • CJLinst Level 1 (0 points)
    Or python:

    import mailbox
    import csv
    writer = csv.writer(open("mbox.csv", "wb"))
    for message in mailbox.mbox('mailbox.mbox'):
    writer.writerow([message\['message-id'], message\['subject'], message\['from']])
  • Barney-15E Level 8 (46,319 points)
    This applescript will work directly into Excel:
    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
    set theMessages to messages of junk mailbox
    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