Skip navigation

Extracting email addresses

783 Views 3 Replies Latest reply: Jan 3, 2013 6:38 AM by Ju.Les RSS
cinan27 Calculating status...
Currently Being Moderated
Mar 26, 2012 5:48 AM

I am trying to extract only email addresses out of Mac Mail so I can then use as input into address book or a mass mailer app.  I have about 10,000 emails that need to be scanned.  I have found an applescript at https://discussions.apple.com/thread/2357203?start=0&tstart=0 which seems to have the right intent but not being an applescript expert when I run it it only creates a new workbook with the correct column headings and no content.  Can someone help me to run this and how I point it at the right mailbox.  I have about 7 different mailboxes which hold emails received about a particular product which is the title of the mailbox (eg red product, black product).  I figure I can produce an excel file for each mailbox and then join them togetehr adding a new column called product and populating it for the added products.  HELP !!!

 

Andrew.

Mail
  • fane_j Level 4 Level 4 (3,655 points)
    Currently Being Moderated
    Mar 26, 2012 6:34 AM (in response to cinan27)

    cinan27 wrote:

     

    I have about 7 different mailboxes

    Looks like Barney-15E, the author of the script, has moved on to bigger and better things (ie, the Lion forum), so I took the liberty to modify his script.

     

    You need to modify the theBoxes property to reflect the names of the mailboxes in question. The mailboxes themselves must not be inside other mailboxes (folders).

     

    If all goes as expected, the single Excel file should contain all the information; there'll be no need to join anything. However, processing 10k messages takes a good while, so you'll have to be patient.

     

    --script begins

    property theBoxes : {"mailbox1", "mailbox2", "mailbox3", "mailbox4", "mailbox5", "mailbox6", "mailbox7"}

     

    on run

     

              set theMessages to {}

     

              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 aBox in theBoxes

                                  set theMessages to theMessages & messages of mailbox aBox

                        end repeat

     

                        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

     

    end run

     

    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

    --script ends


  • jlantern Calculating status...
    Currently Being Moderated
    May 20, 2012 2:57 PM (in response to fane_j)

    could you help me retrieve to, bc and cc email addresses?

     

    I tried [by changing your script - I know nothing of script language]

     

    --script begins

    property theBoxes : {"RWG Archive", "NRW Archive", "Contacts#Newspaper List", "JOBS R", "JOBS N"}

     

    on run

     

              set theMessages to {}

     

              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 "Recipients"

              end tell

     

              tell application "Mail"

                        set theRow to 2

                        get mailboxes

      --set theMessages to messages of junk mailbox

                        repeat with aBox in theBoxes

                                  set theMessages to theMessages & messages of mailbox aBox

                        end repeat

     

                        repeat with aMessage in theMessages

                                  my SetRecipients(recipients of aMessage, theRow, theSheet)

                                  my SetSubject(subject of aMessage, theRow, theSheet)

                                  set theRow to theRow + 1

                        end repeat

              end tell

     

    end run

     

    on SetRecipients(theRecipients, theRow, theSheet)

              tell application "Microsoft Excel"

                        set theRange to "A" & theRow

                        set formula of (range theRange) of theSheet to theRecipients

              end tell

    end SetRecipients

     

    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

    --script ends

     

    I get this error message:

     

    error "Can’t make «class trcp» 1 of «class mssg» id 135522 of «class mbxp» \"RWG Archive\" of application \"Mail\" into the expected type." number -1700 from «class trcp» 1 of «class mssg» id 135522 of «class mbxp» "RWG Archive"

  • Ju.Les Calculating status...
    Currently Being Moderated
    Jan 3, 2013 6:38 AM (in response to jlantern)

    Hi guys, I'm trying to use this script to export all senders email addresses from various mailboxes in Mac mail. Each time I run the script, Applescript tells me: Mail got an error: Can’t get mailbox "Name of the mailbox". What can I do? Is the name of the mailbox the name in the description field? Please help.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.