How can I export a list containing e-mail addresses for everyone that has sent me an e-mail? I have all of the messages archived.
-
deep-email-extractor.com is your friend. Paid for but safe, secure and uses two step passwords. I bought it a few years ago and still use it, quite handy– tinmacJun 2, 2017 at 9:06
-
I can't post an answer yet (not enough rep), but this Jerry Neumann's answer here in Python works wonderfully!– BasjJul 21, 2017 at 11:56
-
I'd suggest checking out SigParser. It does it without all the coding and they don't sell your data like some other products out there.– Paul MendozaJan 2, 2020 at 1:52
10 Answers
I am quite surprised by all the complicated answers implying some extra tools! Every email you receive has its address added to "All contacts" (as opposed to "My Contacts") in the Contacts part of Gmail. Export that one and you're done (or I missed something in your question).
-
That would work great, assuming the person still has access to the Gmail account rather than a simple archive of the messages. Good solution!– BradDec 29, 2014 at 16:12
-
Yes agreed but there is one caveat to using contacts over extract tools, you may have messed with your contacts, a lot of us do when we 'tidy up' as the OP suggests as his messages are archived. At this point you are now not sure if you have 'all' your email addresses? I was in this situation and having looked at all answers here the starbanana one was quite simply the most elegant and trustworthy (it uses two step auth and app specific passwords) and a direct connection from my PC to gmail so no man in the middle listening.– tinmacMar 8, 2015 at 9:17
-
2This is only true if you have that setting turned on. While it's the default, you can easily turn it off. See: Stop Gmail from automatically creating contacts– aleMar 12, 2016 at 18:27
-
This is where the power of Google Apps Script kicks in. If you paste the following script in a new Google Spreadsheet (Tools, Script editor, press the bug icon to authenticate the script), then new sheets will be automatically created based on the number of labels present. After that, the e-mail addresses will be added.
function getEmails() {
// set spreadsheet and retrieve labels
var ss = SpreadsheetApp.getActiveSpreadsheet();
var labels = GmailApp.getUserLabels(), emptyLabels = [];
// itterate through the labels
for (var i=0; i<labels.length; i++) {
try {
// create sheets and clear content
var sh = ss.getSheetByName(labels[i].getName()) ||
ss.insertSheet(labels[i].getName(), ss.getSheets().length);
sh.clear();
// get all messages
var eMails = GmailApp.getMessagesForThreads(
GmailApp.search("label:" + labels[i].getName()))
.reduce(function(a, b) {return a.concat(b);})
.map(function(eMails) {
return eMails.getFrom()
});
// sort and filter for unique entries
var aEmails = eMails.sort().filter(function(el,j,a)
{if(j==a.indexOf(el))return 1;return 0});
// create 2D-array
var aUnique = new Array();
for(var k in aEmails) {
aUnique.push([aEmails[k]]);
}
// add data to corresponding sheet
sh.getRange(1, 1, aUnique.length, 1).setValues(aUnique);
} catch (e) {
emptyLabels.push(labels[i].getName());
}
}
ss.toast("These sheets are empty: " + emptyLabels);
}
Use the SPLIT
function to extract names to find duplicates. System folders are ignored, like INBOX
or All Items
.
Note: script might take some time to execute, which is, of course, dependent upon the number of e-mails
-
@MG1 checked the script and it fails on empty labels. Revised code so that a message will appear, mentioning the empty labels. Jun 4, 2013 at 20:54
Based off of @jacob-jan-tuinstra's answer. Made some minor modifications to suit my needs perhaps others would find it useful.
Uses search, doesn't break up by labels and also does chunking for large inboxes.
The part that says 'YOUR GMAIL SEARCH QUERY GOES HERE' can be filled with any query you would use in your inbox.
function getEmails() {
// set spreadsheet and retrieve labels
var query = 'YOUR GMAIL SEARCH QUERY GOES HERE',
ss = SpreadsheetApp.getActiveSpreadsheet(),
sh = ss.getSheetByName(query) || ss.insertSheet(query, ss.getSheets().length),
uniqueEmails = {},
errors = [],
// max chunk size
chunkSize = 500,
currentChunk = 0,
threads,
messages,
i,
j,
k,
msg,
tos;
sh.clear();
while (currentChunk === 0 || threads.length === chunkSize) {
try {
// grab threads that match the query one chunk at a time
threads = GmailApp.search(query, chunkSize * currentChunk, chunkSize);
// grab corresponding messages from the threads
messages = GmailApp.getMessagesForThreads(threads);
for (i = 0; i < messages.length; i++) {
msg = messages[i];
for (j = 0; j < msg.length; j++) {
// get the from
uniqueEmails[msg[j].getFrom()] = true;
// get the reply to
uniqueEmails[msg[j].getReplyTo()] = true;
// grab from the to field as well
// this has a bug for people with commas in their names
// tos = msg[j].getTo().split(',');
// for (k = 0; k < tos.length; k++) {
// uniqueEmails[tos[k]] = true;
// }
}
}
currentChunk += 1;
} catch (e) {
errors.push(e);
}
}
// create 2D-array
var aUnique = [];
for (k in uniqueEmails) {
aUnique.push([k]);
}
// add data to corresponding sheet
sh.getRange(1, 1, aUnique.length, 1).setValues(aUnique);
}
-
your scrpit works perfectly for me, thanks! can you add the option to retrieve email addresses from the body of the email as well, much appreciated. thanks.– user74582Jul 16, 2014 at 6:19
-
getFrom()
method return the sender of the message in the formatSome Person <someone@somewhere.com>
. If you need just the email address portion of the string, you can add this regular expression like thisgetFrom().replace(/^.+<([^>]+)>$/, "$1")
. Same for .getReplyTo() Apr 15, 2021 at 11:46
Update 2017
Starbanana has changed their name to deep-email-extractor and it also looks like revamped the App UI and made it work on multiple accounts (discovered having just logged in to my app), changed link below to reflect this.
Original Answer
If you need a fast desktop app (not a script) then consider this.
I did quite a bit of searching for an app that works at label level and found Gmail Email Exporter from deep-email-extractor.
It's a paid app (I have nothing to do with them) but it's cheap and you get to export email addresses from specific labels or all your Gmail account.
So in your case put all your email received into a label using a filter and use the above to export to a CSV file.
-
1A cheaper alternative for Mac users is Email Contacts Extractor (itunes.apple.com/us/app/email-contacts-extractor/…). Full-disclosure: I developed it myself because I felt other offerings were too expensive or required online access to my email.– hpiqueJul 11, 2013 at 9:37
-
It would be awesome if you could do a version for 20 addresses or fewer, like they do. Sep 17, 2013 at 22:40
-
starbanana.com now extracts emails out of the body too, I just tried it and the multi-threading also (does 15 labels at the same time) incredibly fast well impressed.– tinmacNov 9, 2013 at 16:41
Confused / Non-Technical / No Idea what to do?
Try the following step by step, and thanks to https://webapps.stackexchange.com/a/47930/6329
step 1. drive.google.com
step 2. new spreadsheet
step 3. tools > script editor
step 4. close the introduction pop up with the close button
step 5. paste in the code
function getEmails() {
// http://stackoverflow.com/a/12029701/1536038
// get all messages
var eMails = GmailApp.getMessagesForThreads(
GmailApp.search('after:2012/1/14 before:2013/8/15'))
.reduce(function(a, b) {return a.concat(b);})
.map(function(eMails) {
return eMails.getFrom()
});
// sort and filter for unique entries
var aEmails = eMails.sort().filter(function(el,j,a)
{if(j==a.indexOf(el))return 1;return 0});
// create 2D-array
var aUnique = new Array();
for(var k in aEmails) {
aUnique.push([aEmails[k]]);
}
// add data to sheet
SpreadsheetApp.getActiveSheet().getRange(1, 1, aUnique.length, 1)
.setValues(aUnique);
}
step 6. position your cursor on within the word "getEmails" in the first line
step 7. click the play triangle button above in the menu bar
step 8. It asks you to authenticate, do that
step 9. click the play button again if it didn't already run
step 10. check your original spreadsheet and it will have the emails.
- Navigate to the list. Choose the checkbox option dropdown, and select all.
- [At the top you will get a hyperlink option to choose all conversations in your list. Click it.] Update: This step doesn't work, it will only let you do 25 at a time, bummer!
- Then go under the More dropdown and choose filter messages like these.
- In the filter dialogue, the From textbox will be highlighted. These are all the from addresses.
- Copy it.
- Paste it into an HTML editor like Notepad++ or Visual Studio.
- Now you just need to do a search and replace the word OR, replace with
;
or,
. - Recopy the list and paste into your message.
-
Better to just give the answer. No need for the story behind it. :-)– Yosi MorAug 16, 2013 at 0:07
The only way to do this is
- Export all as .txt (see: Export Gmail messages to text or HTML files)
- Loop through all of it and grep "From: " lines in a separate database.
Note: if you use imapsize (free) for step 1 then save the backups as "%FROM - The sender of the email" and you have them in plain sight in your directory.
I figured out a way to do this for Mac users using Mac Mail and address book without needing to download extra software. This works with Mac Mail 4.6 and Address Book 5.0.3. Not sure if it works for other vers or not. This may work similarly for other IMAP Email programs like Thunderbird, but I can't vouch for that.
Here are the steps:
- Set up your Gmail account in Mac Mail. Make sure the incoming mail server is "imap.gmail.com" You can find this under the toolbar>Mail>Preferences>Accounts.
- In Gmail, create a Label for the emails for which you want to extract email addresses.
- In Gmail, label all the emails you want per Label above.
- In Gmail, go to Settings>Labels and tick off the box for the new Label you created that says "Show in IMAP."
- Restart Mac Mail so the new Gmail Label syncs.
- Open Address Book. If you use Address Book for your contacts you'll need to back up your contacts because you need to delete all contacts in Address Book. I believe you can do this with File>Export>Address Book Archive. I don't use Address Book other than for exporting Gmail emails so I can't give good advice on this. Delete Address Book contacts at your own risk.
- In Address Book, delete all your contacts. You should be able to do this by selecting one contact, pressing Command+a and pressing the delete key.
- In Mac Mail, find your IMAP folder. There should be a column on the left side of the window with all your Mailboxes. If not go to the top toolbar, select View>Show Mailboxes or press Command+Shift+M. The IMAP folder will be toward the bottom of the column below "Reminders", "RSS", "On My Mac" etc. You should see the Name of your Gmail account you set up earlier with a dropdown arrow on the left.
- In Mac Mail, click the dropdown arrow next to your mailbox. This will show you a list of folders and should show the Label you created in Gmail as a folder. Select this folder by clicking it.
- In Mac Mail in the Messages window, which should now display all your emails for you Gmail Label), select all the emails in the list. Go to the top toolbar, select Messages>Add Senders to Address Book or press Shift+Command+Y. All the senders for your Gmail Label should now be in Address Book.
- In Address Book you can now export contacts as vCards to use in whatever program you like by going to the toolbar and selecting File>Export>Export vCards. You can even import back into Google Contacts. If you need a CSV file, unfortunately you will need to import the vCards into another program (Google Contacts works) and re-export because you cannot export CSV from Mac Mail.
Hope this helps! It's a bit cumbersome, but works for me and is pretty easy after you do it a couple of times.
MineMyMail fetches all of your messages via IMAP and then extracts the email addresses from it.
You can choose which folders it searches by selecting the "Sent Mail" folder/label.
-
Is MineMyMail trustworthy? I went to their site and Chrome warned me that the certificate has expired. Not having a proper HTTPS certificate and asking users to enter their Gmail username and password is definitely scary. It leads me to suspect that the site might extract the emails and use it for their own spamming or selling to other spammers. Feb 3, 2014 at 18:52
IMAP Addresses Exporter is a Mac App that connects to any IMAP email account and extracts every sender address, also from folders/label you set previously. In all fairness, I have to highlight that it is developed by my company.