8 Replies Latest reply: May 28, 2009 10:41 AM by V.K.
mmanik Level 1 Level 1 (0 points)
I have received and sent thousands of emails and they are stored in the inbox and other folders in Apple Mail. I now have a need to have all those email addresses from people that I have received / sent the mail in a csv or txt file. Can anyone give me a solution as to how I can achieve this? Note: I need to do this without having to go through manually saving them in the address book because the address book will have all of these in addition to the ones I have there already. I need to do this so I can sort out the ones I need and only keep those in the address book + have a database that I can sort and use for my newsletters. Thanks.

Mac Air, Mac OS X (10.5.6)
  • 1. Re: How to extract all email addresses from emails received/sent through Ma
    Ernie Stamper Level 8 Level 8 (37,475 points)
    Hello and welcome to the Discussions.

    You need to open the Previous Recipients data, and then process those not already in the main Address Book -- see:

    http://docs.info.apple.com/article.html?path=Mail/3.0/en/9976.html

    Note that those already in the AB have an icon for that beside them. Also note this will only have addresses you have sent to, and not those addresses you have only received email from.

    Ernie
  • 2. Re: How to extract all email addresses from emails received/sent through Ma
    mmanik Level 1 Level 1 (0 points)
    Thanks Ernie,

    At least that allows me to get all the email addresses of the people I have sent mails to, however, before I do that and crowd my address book, will it give me an option to save all these in a new folder that I create in the address book or will it just dump it in the main directory? Thanks in advance.
  • 3. Re: How to extract all email addresses from emails received/sent through Ma
    mmanik Level 1 Level 1 (0 points)
    I will still need someone with a solution that allows me to save all the email addresses that I have received mail from.
  • 4. Re: How to extract all email addresses from emails received/sent through Ma
    V.K. Level 9 Level 9 (56,120 points)
    mmanik wrote:
    Thanks Ernie,

    At least that allows me to get all the email addresses of the people I have sent mails to, however, before I do that and crowd my address book, will it give me an option to save all these in a new folder that I create in the address book or will it just dump it in the main directory? Thanks in advance.

    that will just dump them in the main directory of the AB. you can extract them directly into a text file without importing into AB using some scripting. see this link for example
    http://macscripter.net/viewtopic.php?id=23807
  • 5. Re: How to extract all email addresses from emails received/sent through Ma
    V.K. Level 9 Level 9 (56,120 points)
    mmanik wrote:
    I will still need someone with a solution that allows me to save all the email addresses that I have received mail from.

    that will be much tricker because you'd need to write a separate script for that and also there are a number of things you would want to exclude such as various Spam and junk mailboxes. surely you don't want the addresses from those?
  • 6. Re: How to extract all email addresses from emails received/sent through Ma
    Ernie Stamper Level 8 Level 8 (37,475 points)
    You can select multiple messages (even All), then click on Message in the Menubar and choose add senders to AB. But this will be pretty non selective.

    Ernie
  • 7. Re: How to extract all email addresses from emails received/sent through Ma
    mmanik Level 1 Level 1 (0 points)
    True V.K. I do not want all the email addresses from the spam that I have received! But I guess that this point that is better than nothing at all.
  • 8. Re: How to extract all email addresses from emails received/sent through Ma
    V.K. Level 9 Level 9 (56,120 points)
    I don't know how to gracefully exclude all mailboxes that need to be excluded but the following will work on any one mailbox.

    paste the following into Script Editor

    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 335px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Mail"
    set mlist to selection
    set cur_mbox to mailbox of item 1 of mlist

    repeat with msg in messages of cur_mbox

    do shell script "echo " & quoted form of (sender of msg as text) & ">>~/.list.txt"

    repeat with addr in (address of recipients of msg as list)

    do shell script "echo " & quoted form of (addr as text) & ">>~/.list.txt"
    end repeat

    repeat with addr in (address of cc recipients of msg as list)

    do shell script "echo " & quoted form of (addr as text) & ">>~/.list.txt"
    end repeat

    repeat with addr in (address of bcc recipients of msg as list)

    do shell script "echo " & quoted form of (addr as text) & ">>~/.list.txt"
    end repeat
    end repeat

    end tell

    do shell script "cat ~/.list.txt |sort|uniq >~/desktop/list.txt; rm ~/.list.txt"</pre>


    select a message in a mailbox you want to process and press "run" in Script Editor. It will take a VERY long time to process so be patient. in the end it will create a file list.txt on your desktop with all "To" and "From" emails from that mailbox.