Applescript for Mac Mail Email Addresses

Hey guys,
Bit of help with scripting here would be awesome:
I have been trying to collate all the email addresses located in my Mac Mail accounts. To do this I have used the following in Applescript:
tell application "Mail"
set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage))
repeat with eachMessage in theseMessages
set theFrom to (extract address from sender of eachMessage)
do shell script "echo " & quoted form of theFrom & return & " >> ~/documents/extracted.txt"
end repeat
end tell
This has worked really well, but I would also like the addresses of people I have sent mails to (sent mail account) and also any addresses that are CC'd in emails.
I have played around with the script, but my little knowledge of the program meant I got only errors! Any help on obtaining these final email addresses would be much appreciated.
Best regards,
Simon

While the script works, two problems are that there are many duplicate email addresses and the list is not sorted.
The following addresses these problems (and avoids repeated do shell script calls):
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;"
title="this text can be pasted into the AppleScript Editor">
tell application "Mail"
set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage))
set listOfEmails to {}
repeat with eachMessage in theseMessages
try
set theFrom to (extract address from sender of eachMessage)
if listOfEmails does not contain theFrom then
copy theFrom to the end of listOfEmails
end if
if (address of to recipient) of eachMessage is not {} then
repeat with i from 1 to count of to recipient of eachMessage
set theTo to (address of to recipient i) of eachMessage as string
if listOfEmails does not contain theTo then
copy theTo to the end of listOfEmails
end if
end repeat
end if
if (address of cc recipient) of eachMessage is not {} then
repeat with i from 1 to count of cc recipient of eachMessage
set theCC to (address of cc recipient i) of eachMessage as string
if listOfEmails does not contain theCC then
copy theCC to the end of listOfEmails
end if
end repeat
end if
end try
end repeat
end tell
tell application "Finder" to set ptd to path to documents folder as string
set theFile to ptd & "extracted.txt"
set theFileID to open for access theFile with write permission
set SortedListOfEmails to simple_sort(listOfEmails)
repeat with i from 1 to count of SortedListOfEmails
write item i of SortedListOfEmails & return to theFileID as «class utf8»
end repeat
close access theFileID
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</pre>

Similar Messages

  • I want to use Mac Mail for my work email address, which containts multiple outbound options (i.e. hr@, me@ etc). Is there a way to set up Mac Mail to have an account with multiple outbound addresses rather than adding in multiple accounts?

    I want to use Mac Mail for my work email address, which containts multiple outbound options (i.e. hr@, me@ etc). Is there a way to set up Mac Mail to have an account with multiple outbound addresses rather than adding in multiple accounts?

    This sounds like the age old problem with keychain & Safari. I don't know of a way to solve it without using something like 1Password.
    The iOS app has it's own built in browser, so it has more control over what gets autofilled. Safari on OS X has an 1Password extension that handles account selection & autofill etc.
    Keychain is great in principle, but it quickly falls down when you need tight integration with many ID's & different use cases (work, home etc).
    I'd suggest you submit feedback to Apple about your thoughts. I did so years ago about this issue & this is how far we have come (back to the point where me.com synced passwords) :^)
    http://apple.com/feedback/macosx.html
    Other tools like lastpass or keypassx may also help if you want to truly segregate password storage, but that doesn't fix autofill, the way around that issue is to dedicate one browser for work.

  • "Enter the Yahoo! password for [my yahoo email address]" keeps popping up on my Mac desktop

    A pop-up window "Enter the Yahoo! password for [my yahoo email address]" keeps popping up on my Mac desktop (Leopard OS) every few hours. This has happened for the past year and only happens on my MacPro desktop, never on other laptops/computer. Does anyone have solution please ?

    Ok !! I think I finally found the trouble of this !! I went crazy that every 5 seconds I had to fill in my password for my yahoo account om Apple Mail. My computer is in another language so I'll try to translate as good as possible the buttons and so ..
    So these are the steps required:
    You need to give computer access to the password of Yahoo.com. How to do so ?
    You go to the application "Key Chain" that is included in your MacBook Pro.
    Then you go to the first tab that should say something with "Login/Session" and you should see all your saved passwords.
    Scroll down to the saved password of  "Yahoo: your-username @ ...
    Click on it, you should see a window opening
    Go to the tab "Access Control"
    Then click on "Allow all applications to connect .. ", NOT the option "Ask every time for allowance" or you can also just add the program "MAIL" with the "+" icon !!
    There you go, now you should not have to worry again !!!!!!
    Hope it helps people !!!

  • I have installed OS Maverick 10.9 and now find titles are included for mac mail addressees. That is, I get Dr John Brown instead of John Brown. That did not happen before. How do I suppress the title?

    I have installed OS Mavericks 10.9 and now find that Mac Mail includes titles for addressees. Thus, it shows 'Dr John Brown' instead of 'John Brown'. I have had the same problem with suffixes with earlier versions and solved that by deleting all suffixes from my address book. I don't want to have to do that for titles. How can I keep the titles in my address book but have them not show for Mac Mail addressess?

    I have the opposite problem, Barry ... now only the eMail address shows ... no name at all, even though I type it in!

  • Individual mailboxes for .mac mail

    I love this software. The only thing i'm trying to figure out is how to create individual mailboxes for each alias I've created. I would love to have each alias mail delivered to its appropriate box. If you can give some feedback on this topic I'd really apreciate it.
    Thanks

    Assuming you are referring to a .Mac account alias email address, messages addressed to your .Mac email alias will arrive in your .Mac account inbox which cannot be changed. All mailboxes under Inbox, Drafts, Sent, Trash and Junk in the Mail.app mailboxes drawer are created and managed automatically by Mail.
    You can create an "On My Mac" location mailbox for each alias email address and then create a Rule in Mail to automatically transfer messages addressed to an alias email address to the designated mailbox for the address but none of these mailboxes will be located under Inbox in the mailboxes drawer.

  • HT1349 how can I change an email for authorization, the email address we used years back, is no longer a valid email address

    how can I change an email for authorization, the email address we used years back, is no longer a valid email address

    SfromW wrote: ... how can I change an email for authorization, the email address we used years back, is no longer a valid email address
    How to change account here: http://support.apple.com/kb/PH1641
    If you need more help, start here: http://www.apple.com/support/itunes/
    SfromW wrote: ... we can't remember the password from the old email address (for authorization)...
    Help Retrieving and changing passwords here: http://support.apple.com/kb/HT1911
    If you need more help, from iTunes for Windows, click  iTunes > iTunes Store > Support
    SfromW wrote: ... apple should make it easier to transfer authorization authority....I would think anyways.
    You might want to rethink your thoughts about making transferring authority easier.  Making it too easy would certainly degrade your account's security.  If you still believe it should be easier, you can send feedback directly to Apple via http://www.apple.com/feedback/itunesapp.html
    You will not get a response, but you can be certain that the responsible Apple people will see your input for consideration in FaceTime product development.
    As a new user, please understand that you are NOT directly addressing Apple here.  For more info about Apple discussions, start here: http://discussions.apple.com/static/apple/tutorial/etiquette.html 
    Message was edited by: EZ Jim
    Mac OSX 10.7.4

  • Return receipt plug in for Mac Mail software?

    Return receipt for Mac OSX 10.4.6 build in email software “Mail” 2.0.7 (746.2/749.3) 2005 Apple Inc.
    Is there a return receipt plug in for Mac Mail software? I want to know if my sent mail was received and know if the mail was opened.

    Kboo,
    in general not a good idea. This may cause loops with Out-of-Office responders and also not a very trustworthy confirmation.
    Options are to use certified email servers as an intermediate (google to find many) or to request explicitly a written reply from the recipient.
    See also this post (there are many more when you search here)
    http://discussions.apple.com/message.jspa?messageID=713245#713245

  • Profile update should allow for change of email address

    Dear sirs,
    Member profile update should allow for change of email address otherwise one has to unsubscribe their old email address and re-subscribe the new one.
    Please make it happen.

    I worked out the answer to my own question.
    1. Logged into my Apple ID
    2. Editited my Apple ID email address (old) and changed it to my @me.com address (ignored the red warning about Apple ID must not use a domain owned by Apple) and pressed the blue Save Changes button anyway at the bottom of the page.
    This created a new Primary Email Address with the @me.com (which needed to be verified etc.)
    The Primary Email Address can now also be changed to my @icloud.com address if I wish (which also needs to be verified.
    I would now like to be able to use the option to 'Make my Apple ID and Prmary email address one and the same'. So I can finally get rid of my old e-mail address as my Apple ID. It can give me the option to change it to my @icloud.com address, but when I press submit, it does not do anything. This feature does not seem to work yet. I suppose that is another question / request.

  • Archiving Mac Mail emails per year

    hello
    is there an easy way ( read: automatic, by script ;-) to archive my Mac Mail emails per year ?
    thx in advance
    Henny

    As I looked back at my test Smart Mailbox, you could use something like that to group them all and then move them into the new Year hierarchy which would sort of semi-automate the process.
    Build your 2010 hierarchy and then create the 2010 smart mailbox for a particular folder in your archive. Select all in the smart mailbox and move to the new 2010 folder of same name. Edit the smart mailbox for each folder and repeat. Sounds a bit tedious, still, depending on how many subfolders you have and how many years you go back.
    And more ideas. I created a 2010 Smart Mailbox that got all emails for 2010. I then typed in one of my Archive folder names in the Search box and selected Mailbox as the criteria type from the search dropdown. So, for instance, if I wanted to look at my online orders from 2010, I selected the 2010 smart mailbox, and then typed Online Orders into the search field. When the various matching criteria popped up, I selected Mailboxes. 
    This method would allow you to keep your Archive grouping neatly organized and not have the hierarchy duplicated each year. Smart Mailboxes can be grouped by dragging them on top of one another, so you could keep the Year mailboxes neetly organized, also.

  • Where can I find free Christmas stationery for Mac Mail version 6.2?

    Where can I find free Christmas stationery for Mac Mail version 6.2 on my MacBook Pro running OS 10.8.2??? Everything I've tried to download is from 2008-2009 and isn't compatible.
    ~Patty

    Dear sig,
    Thank you for responding. When I Googled, I received a list of suggested web sites, but they were all posted in 2008-2009 and, when I downloaded the application, they were not compatible with OS 10.8.2 and/or Mail 6.2. I did find an app in the App Store called "Stationery for Mail" for $6.99 (less expensive than equinux or ipresentee) that had one Christmas email template and several others for other occasions/seasons. I purchased that one so that I'd have at least one email template to use for now, but I'd love to find more templates for future use that are FREE.
    I can't believe Apple hasn't created more email stationery templates for download (freeware) on its web site. I can find screensavers and wallpapers, but nothing for Mail.
    If you or anyone else finds or knows of a website with FREE email stationery templates for Mail 6.2, please let me know.
    Thank you!
    ~Patty

  • Smtp auth. fails for Mac mail but ok for netscpae mail ???

    Hello all,
    I am having some persistent problems with SMTP authentication to send mail from my Mac via my ISP onto the internet.
    What DOES work:
    1. sending and receiving mail from my current ISP account using Netscape mail.
    2. receiving mail from my ISP account using Mac mail
    What DOES NOT work:
    3. sending mail via my ISP using Mac Mail. The error message is that the SMTP authentication failed.
    Yes, I checked the mail port (25) and the smtp address (in plain text ascii)
    Has anyone had a similar problem, where Mac mail failes, but another mail tool succeeds? Has anyone succeeded at getting it to work for Mac mail?
    Thanks,
    Ary
    Powerbook G4   Mac OS X (10.3.9)  

    If your ISP requires POP before SMTP authentication which requires checking the account's incoming mail server for new mail before being able to send with the account's SMTP server (checking the account for new mail should be required once per session only), then authentication for the SMTP server should be set to None.
    Go to Mail > Preferences > Accounts and under the account information tab for the account preferences at the SMTP server selection, select the Server Setting button below.
    If Password is selected for SMTP authentication, change it to None and test if this resolves the problem.
    If None is selected and your ISP requires password authentication for their SMTP server, select Password and enter the account's user name and password required for the authentication.

  • Flexfield for Supplier's email address in 10.7NCA

    Anyone using a flexfield for Supplier's email address in 10.7NCA AP?
    We want to record an email for the Supplier which we can use to send PO. But we are on MSOB and to upgrade to 11i would take some time.
    Reading the manuals on Flexfields, but if someone has any tricks, pls let me know.
    Thanks
    Mandar

    Hello Pankaj,
    it should be a valid E-Mail Address because you should be able to handle the bounces. And please have also a look at <a href="/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface">Sending E-Mail from ABAP - Version 610 and Higher - BCS Interface</a> if your Mail system is configured correctly. You should be able to send out SMTP Mails via SAP Business Workplace.
    Regards
    Gregor

  • Support for  catch all email address

    Does anyone know if mail server has support for  catch all email address

    I now do want to catch all email as it has become my lives work to report spam.
    So I figured out an easier way to catch all email using simply the serveradmin command-line tool (this only takes email that would otherwise bounce):
    sudo serveradmin settings mail:imap:lmtp_luser_relay_enabled = yes
    sudo serveradmin settings mail:imap:lmtp_luser_relay = catchallusername
    sudo postfix reload

  • Smileys for mac mail

    Hello - does anyone know how to get smileys for mac mail? I went to smileycentral but im pretty sure its just for windows/pc users. I need to pimp out my mail. any suggestions?

    Hi, the easiest way with OSX Mail is to have a Folder/Window of Emoticons open the just drag & drop into the eMail you're composing

  • Emoticons for mac mail

    Does anybody know where I can get emoticons (smiley faces) for mac mail?
    Too bad mac mail doesn't have that feature, one that stupid pc email software has build in.

    They are easy enough to google for.
    In Mail you have to add them as attachments.

Maybe you are looking for

  • K7N2 Delta - hope this is of some help

    M/B K7N2 Delta - ILSR AMD XP 3200+ CORSAIR XMS 2 x 256mb DDR400 ATI 9600XT 2 x 200GB MAXTORS 450 w PSU I've had several years experience in building my own PC's, and I suppose like everyone else I've learnt some expensive lessons.  At the moment I've

  • Switching from Entourage to ical, mail, and address book- duplications?

    I am tired of the slowness of Entourage and was thinking of switching to all of the native mac programs. Any suggestions or comments on whether this is a good idea or not? Also, will all of my information be duplicated. I have about 3 gigs of informa

  • Get data every 2 columns at a time in excel

    i would like to read the following excel file and plot every 2 columns at one time given an interval. for example at 7 am i ll plot corresponding I and V and at 8 am so on.. but even though i programmed my VI to read by increasing index 0,2,4 so on i

  • IPhone Photos App Photo Library has no Delete button

    iPhone 4S iOS 6.1.3 Photos App Photo Library Album Pictures have no Delete button in the bottom right bottom corner like found in Camera Roll Album Pictures. How do I delete obsolescent photos on the iPhone Photo Library Album without sync deleting i

  • RHTML 8 WebHelp Search in Chrome not working

    We are running RoboHTML 8, with output to WebHelp. The project does include PDF files. I mention this because of other Discussions I've read looking for a solution. The output is delivered to customers in a WAR and it serves just fine from the server