Apple Event: May 7th at 7 am PT

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

Extract email addresses from email header - Sender (From) - Mail

Hi!

I would like to extract email addresses from email header from field "Sender (From)" and from email body in Mail at the same time.

I saw only scripts how to extract from email body.


I get emails asking for some informations about product and many people don't include their email address in the body, so I have to extract from email header as well.


I would like to extract email addresses from whole email account, separate alphabeticaly, delete duplicates and save it (separated by comma) in text file.

This I would use for sending massive email to all customers.

I'm on OSX 10.6.8.

Do you have please somebody script for extracting email addresses in the way:

1. select mail account

2. run script

3. save email addresses to txt file


Thank you for help and advise!

MacBook Pro, Mac OS X (10.6.8)

Posted on Mar 24, 2013 5:25 AM

Reply
29 replies

Mar 27, 2013 3:19 PM in response to Neville Hillyer

The output has only a few addresses - identic result like I got before switching off "Use Smart Addresses".


Same like before:


It can extract to .txt file only email addresses from email header which includes after the name as well email address.


Example:

From: Neville Hillyer <n.hillyer@gmail.com>


If there is in header only the name without the email address then it's not extracted (email is visible after secondary click on the name)


Example:

From: Neville Hillyer


I just checked that most of emails I have has in the emailheader only the name without the email address so I miss most of email addresses.


Now are extracted only email addresses from emails where was originally email address included in the header before swiching of "Use Smart Address".

Even if now ALL emails include in the header email address.

Apr 27, 2013 11:02 PM in response to Neville Hillyer

Dear Neville,


I have hundreds of email received / sent to various people sent whose accounts are in the same email server, for example @xyz.gov.in


I need to search and extract the following header information:


From:

To:

Cc:

Bcc:

Date & Time:

Subject:


Is there any script that can do this for me and create a text or .csv or any other file?


My OS: Mac OS 10.8.3

Apple Mail Version: 6.3


many thanks in advance


Amit

Apr 28, 2013 7:01 AM in response to Neville Hillyer

Dear Neville,


Thanks so much for such a prompt reply. I have started a new discussion here...

https://discussions.apple.com/thread/5001113


I use pop & imap both. Messages are also stored in offline folders in Apple mail.

The emails have been sent / received in more than one account.

All messages are in Apple Mail v6.3. Mac OS 10.8.3


many thanks in advance.


best

Amit

Apr 28, 2013 2:46 PM in response to muzaa

muzaa,


Here is an applescript to extract all the email from (sender from) and then it save it in a text file in Documents and sorts it alphabetically.


tell application "Mail"

set selectionMessage to selection-- just select the first message in the folder

set thisMessage to item 1 of selectionMessage

set allSenders to sender of every message in mailbox of thisMessage

end tell


set listOfEmails to {}


-- End of Original set and beginning of new set


repeat with i from 1 to (count allSenders)


tell application "Mail" to set theFrom to (extract address fromitemi of allSenders)

if listOfEmails does not contain theFrom then

set end of listOfEmails to theFrom

end if



end repeat


set SortedListOfEmails to simple_sort(listOfEmails)

set ptd to path todocuments folderasstring

set theFile to ptd & "extracted.txt"

set theFileID to open for accesstheFile with write permission

try

repeat with i from 1 to count of SortedListOfEmails


writeitemi of SortedListOfEmails & returntotheFileIDas «class utf8»

end repeat

end try

close accesstheFileID


on simple_sort(my_list)

set the index_list to {}

set the sorted_list to {}

repeat (the number of items in my_list) times

set the low_item to ""

repeat with i from 1 to (number of items in my_list)

if i is not in the index_list then

set this_item to item i of my_list as text

if the low_item is "" then

set the low_item to this_item

set the low_item_index to i

else if this_item comes before the low_item then

set the low_item to this_item

set the low_item_index to i

end if

end if

end repeat

set the end of sorted_list to the low_item

set the end of the index_list to the low_item_index

end repeat

return the sorted_list

end simple_sort

Extract email addresses from email header - Sender (From) - Mail

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