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.

Extracting email addresses from the Text Body in Mail

Hello
My customers find products and ideas from my web site. The website sends me an email with their contact email address in the body of the text.
I now want to send information to all my customers (by product group) about how to use the products.
So, how do I extract the email information from the text of the email and put it in a list? I have been cutting and pasting, but it takes too long.
Has anyone got a script which extracts email addresses (or any word containing an "@" symbol) from the body of the email (not from the To: or Cc: or Bcc: fields) which they would be able to share? I can sort and highlight the relevant emails in my mail box by product group and would then like to get that group of results copied into Numbers or Excel where I can edit or delete them if necessary.
I am a Newbie when it comes to writing Apple Scripts and do not know where to start! I have tried email extractor and it does not do the job.
Thanks for any advice!
Rob

iMac 2008 model, Mac OS X (10.5.5), Also have a 15" Macbook Pro

Posted on May 10, 2010 7:56 AM

Reply
3 replies

May 10, 2010 6:59 PM in response to Raltham

The following script should extract all email addresses from the body of the selected messages, and put them into the clipboard. It should then be easy to paste the contents of the clipboard into a Numbers or Excel document.

*set theAddresses to ""*
try
*set TID to AppleScript's text item delimiters*
*set AppleScript's text item delimiters to space*
*tell application "Mail"*
*repeat with theMessage in (get selection)*
*set theText to text items of (get content of theMessage)*
*repeat with thisItem in theText*
*if thisItem contains "@" then*
*set theAddresses to theAddresses & (thisItem as text) & return*
*end if*
*end repeat*
*end repeat*
*end tell*
*set the clipboard to theAddresses*
*set AppleScript's text item delimiters to TID*
*on error*
*set AppleScript's text item delimiters to TID*
*end try*
*the clipboard*

Extracting email addresses from the Text Body in Mail

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