1 Reply Latest reply: Feb 3, 2013 8:24 AM by HD
Niko K Level 1 (0 points)

I am very new to applescript and I am having some teathing troubles.  I am trying to create a list of email addresses from emails arriving into a particular mailbox.  I think I have the logic right,


1. Open Mail

2. Go to the mailbox i need

3. Go to the first message

4. Get the email address

5. Put the address in a text file

6. Repeat for all the emails in the mailbox


I'm stuck on number 2, generally how to select items i need in Mail, any help with this would be great.


If anyone also knows of a good book that might lean towards scripting with Mail, it woud be really helpful.


Thanks in advance!

  • HD Level 4 (3,585 points)



    This question is probably better posted in the Mac OS X Technologies section of these forums, but here goes...


    You don't have to select anything (in the sense of clicking on it or highlighting it). But you do need to specify what you want to work on, and for that you need to read Mail's AppleScript Dictionary.


    Basically you specify the inbox of the mail account you want to work on, and then cast the senders of those messages into a list.


    tell application "Mail"

              set the_senders to sender of every message of mailbox "INBOX" of account "iCloud"

    end tell



    This may take a minute or two depending on how many messages there are in the Inbox and how powerful your Mac is.


    The senders in the resulting AppleScript list will be text strings in the form:


    "Apple Support Communities Updates <discussions-updates@apple.com>"


    or just the email address if the sender doesn't have a display name.


    AppleScript has fairly limited text parsing tools but you should be able to loop through the list casting these into plain email addresses and write them to a text file.


    Hope this helps!