Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to extract all email addresses from emails received/sent through Mail

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)

Posted on May 28, 2009 7:23 AM

Reply
8 replies

May 28, 2009 7:58 AM in response to mmanik

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

May 28, 2009 8:12 AM in response to mmanik

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

May 28, 2009 8:15 AM in response to mmanik

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?

May 28, 2009 10:41 AM in response to mmanik

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.

How to extract all email addresses from emails received/sent through Mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.