Applescript with Mail

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!

Hi,
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 <[email protected]>"
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!
H

Similar Messages

  • Applescript with Mail attachments and shell scripts (pdftk)

    I'm trying to create a script that I can call using mail rules that will:
    1. save an attached PDF file to a folder (folder name is 'PDFs_from_Mail:')
    2. save each page of the PDF as a separate file
    3. delete the old file
    so far, i used the script below called from mail to save the attachments to the
    -- script called from mail
    using terms from application"Mail"
      onperform mail action with messages theMessages
        tell application"Finder" to set ptd to (path to desktopfolder) as string
        tell application"Finder" to set pathToAttachments to(path to desktop folder as string) &"PDFs_from_Mail:"
        tell application"Mail"
           repeatwith theMessage in theMessages
                if theMessage's mailattachments is not {} then
                      repeatwith theAttachment in theMessage's mailattachments
                            settheFileName to pathToAttachments & theAttachment's name
                            try
                                     save theAttachment in theFileName
                              onerror errnum
                            endtry
                      endrepeat
                end if
             endrepeat
          end tell
      endperform mail action with messages
    end usingterms from
    tell application"Mail"
        setmyMessages to selection
        tellme to perform mail action with messages myMessages
    end tell
    -- end of script called from mail
    after the file is in the folder, i'd like to automatically call a script that splits it in to pages and saves each file.  I found pdftk can do what I need.  I got the following working, which uses a folder action script to process the file:
    -- burst script
    on addingfolder items to this_folder after receiving added_items
       tellapplication "Finder"
           set fold_name tothe name of this_folder
               try
                   repeatwith i from 1 to number ofitems in added_items
                          set theFile toitem i of added_items
                          set oldDelimiters toAppleScript's text item delimiters
                          set AppleScript's textitem delimiters to {":"}
                          set theFolder to(((text items 1 thru ((count everytext item of (theFile asstring)) -1)) of (theFile asstring))) as string
                          set AppleScript's textitem delimiters to oldDelimiters
                                --get the file name
                                   set theFileName to the name of theFile
                                                     do shell script"/usr/local/bin/pdftk " & (POSIX path oftheFile) & " burst output " & (POSIXpath of theFolder) & "/" & theFileName &"_%03d.pdf"
                                                      delete theFile
                                                    endrepeat
                                        end try
                         endtell
    end adding folder items to
    -- end burst script
    the shell script that is called is in the format:
    pdftk myfile.pdf burst
    the output parameter basically adds the page number to the end of the original filename for each file that is created
    my idea was to attach the folder action script to the 'PDFs_from_Mail' folder, and when the first script is called, the file would be saved to that folder and trigger the folder action script burst the file.  it works for individual messages, but when I try using it with the hundreds of messages that I have, all kinds of crazy things happen... the filenames are all wrong and it seems like it goes on infinitely.
    My familiarity with applescript is somewhat limited (as you may have guessed) and I'm wondering if there is a better approach.  perhaps if I incorporate the shell script into the script called from mail it may streamline everything.
    my problem is that I am not sure what code I need to keep in each script.
    can anyone take a quick look at this and give me some advice?
    my goal is to have these individual pages in a folder so that I can use quick view to page through them.  if the pdf is more than one page, then I have to get involved in scrolling up/down and it becomes difficult to find things efficiently.
    thanks!

    just a quick update and a general questions about applescripting with shell scripts...
    i attached the above folder action burst script to a folder, and have been dragging pdf files into it, one at a time.
    sometimes the script runs fine and the new files are created and the old pdf is deleted.  other times, there is a long delay between when I drop a pdf file into the folder and when the new files are created.  and sometimes nothing even happens at all (uaually if i dont wait for at least 30 seconds or so between dropping the files in the folder).  I also noticed that the window title text (area showing the folder name at the top of the finder window) becomes grayed out when the script is running and sometimes it remains grayed out for a few minutes after the script has run.
    could it be that the shell script just takes a really long time to work?  i am afraid to drop more than one file at a time as the last time I tried that the output was all wrong and I had to force quit processes and shut down. 

  • Cant send mail via applescript with mail rule

    I created a script that would work as follows:
    I send myself an email. The mail rule opens up an apple script that will take a picture using the isight camera and then email it back to me. It works fine in script editor. When i run it via mail.app it takes the picture but it wont email it back to me.
    Here is my script:
    do shell script "~/Documents/EmailScripts/isightcapture ~/Documents/EmailScripts/snap.jpg"
    tell application "Mail"
    set addrVar to "[email protected]"
    set subjectvar to "Macbook Pic"
    tell application "Finder"
    set the target_file to alias "Macintosh HD:Users:ak406:Documents:EmailScripts:snap.jpg"
    set bodyvar to "Picture from Macbook"
    end tell
    set composeMessage to (make new outgoing message)
    tell composeMessage
    make new recipient at beginning of to recipients with properties {address:addrVar}
    set the subject to subjectvar
    set the content to bodyvar
    tell content
    make new attachment with properties {file name:target_file} at after the last word of the last paragraph
    end tell
    end tell
    send composeMessage
    end tell
    Thanks for the help.

    Hi ak406
    Just tested your script here, less the do shell script part and it worked perfectly from my mail app.
    Budgie

  • Can I get a Read Receipt with Mail, like in Outlook?

    Can I get a Read Receipt with Mail, like in Outlook?
    W.W.

    It is possible, though not through the GUI. And as Dave points out, asking for a receipt does not mean that you will get one. The magic incantations for requesting receipts are detailed, amongst other places, in this article. It requires using the Terminal, and once set affects all messages you send until you unset it again.
    If you search this forum for read receipts (the topic surfaces frequently) you should find a helpful Applescript for turning them on and off, to save using the terminal.
    AK

  • Writing an AppleScript for Mail

    I have never written an AppleScript before, so I don't know if this is even possible. But, here goes...
    I manually process my junk mail by opening each message, clicking on "Long Headers," and forwarding to [email protected] Is it possible to write a script that would allow this process to be automated?
    Thanks.

    You can get the header text with this Applescript:
    Click here to launch Script Editor.
    tell application "Mail"
    the selection
    properties of item 1 of the result
    set thisHeader to all headers of the result
    end tell
    There is a sample Applescript included with Mail.app called "Create New Message.scpt", it should contain snippets to get you going.
    Or Google and there will be plenty of simpler ones. Truth be told, the Apple sample scripts are about the worst for learning from.

  • Applescript for Mail Question

    Is it possible to create an Applescript for Mail, that, when an email with a specific subject line arrives in my inbox, an attached photograph would get sent immediately in response to the person who sent the email.  The subject lines would vary (e.g., people_1, or, places_16).  Every subject line would have a corresponding photo located somewhere on my hard drive (there would be hundreds of possibilities - the catalogue would be concentrated in one place).  So, for example, when "places_21" hits my Mail in box, an email would be generated in response, automatically, with a photo (places_21) attached.  Thank you!  Marcos

    Actually, it's not that hard to do, it's just that there are a lot of use cases, and a lot of caveats to consider.
    For example, do you intend/expect to work from a predefined list of image file names? Or do you want/expect to react to any filename that's requested?
    You say that the files would be 'somewhere on my hard drive'... how does the script know where to look? How does it resolve filename conflicts? What should happen if a file can't be found?
    As fane suggests, you should also consider an audit log, so you can see who asked for what, and when, along with errors that occurred on the way.
    So it's entirely do-able, just a lot of questions to answer before you get started.

  • AppleScript for mail merge

    What is AppleScript for mail merge

    AppleScript is a programming language that is tied to certain Applications that support it. Pages v5.5.1 has a scripting dictionary of the terms it will support via AppleScript. Apple's answer to not including Mail Merge functionality in Pages v5.5.1 is for individual users to roll their own, download an example and adapt it, or use another application with built-in Mail merge features.
    See my previous post to you.

  • The problem I have since I upgraded to Mavericks version 10.9.1 The problem appears only with Mail not with other programs, not even with my browser. When I try to zoom the text of an e-mail I received or sent , I can no longer use the keys Command   to e

    the problem I have since I upgraded to Mavericks version 10.9.1
    The problem appears only with Mail not with other programs, not even with my browser.
    When I try to zoom the text of an e-mail I received or sent , I can no longer use the keys Command + to enlarge the text, although I can reduce it with Command -.
    As I have a problem with my eyes, This is a serious matter for me.
    When I write an e-mail, if I select text and press Command +, it just displaces the text to the right.
    Now, my husband has a USB keyboard. If he connects it to my computer, his regular Command + does not work either, but  he uses the extended keyboard, then it works. Unfortunately, he needs it for a musical application which does not work with a wireless keyboard.

    Firefox 3.6.4 and 3.6.6 use a process called, "plugin-container.exe" which was using up most of my CPU when I opened up multiple tabs that contained Adobe Flash files, and caused Firefox to lock up.
    My solution was to use Firefox 3.5.10 which you can get from the Mozilla website at [http://www.mozilla.com/en-US/firefox/all-older.html]
    I am using Adobe Flash 10.1.53.64 without any problem in this version of Firefox. Check the release notes, I believe it contains all the latest security fixes in "Firefox 3.6.4".
    Hopefully, they will fix Firefox 3.6 in the next version (e.g. Firefox 3.6.7), until then you should probably use "Firefox 3.5.10".

  • How do I use my iPhone's hot spot to send email with Mail ?

    Hi,
    My land line is dead ... so no phone nor internet at home.  But I can use my iPhone'hot spot to get on the web from my iMac.  Great ... it works !
    Oups !   I cannot send email from my computer using my iPhone's hot spot with Mail.
    How do I do that ?
    Regards.
    Robert Lespérance

    Hi Templeton Peck,
    Thanks for droping in my thread ...
    Doesn't the fact that I can surf the web with my iPhone's hot spot and that I cannot use Mail normally has I normally do give you a clue what the problem could be ?
    What other information can I give you other than normally I can surf and send email with my regular ISP.  Now that my ISP is dead I am using my iPhone's hotspot to surf the web awaiting that my ISP's connoection returns. Surfing is OK but I cannot send emails with through Mail.
    When I want to send an email from my computer, I get a message asking me to select the the SMTP server.  Then I select my usual ISP server, but the message comes back telling me it does not work.
    Is there any other configuration to do ?

  • Problems with Mail, Safari and iTunes after updating to 10.5.6

    Hi all,
    after installing 10.5.6 I have problems with Mail, Safari and iTunes.
    The time to open mails, websides and iTunes store is increasing dramatically since the update. If I open a webside parallel with Safari and Firefox, Safari needs minimum 15 times longer to open the complete side. Mails containing HTML-code also needs a long time to be opened. Tha same Problem with iTunes store. Connecting to the Store costs at least 30 - 40 seconds. And unfortunately for every iTunes store side I open. Its terrible
    Any idea or workaroung to solve that problem?
    Regards
    Michael

    First, run Disk Utility and repair permissions and then restart.
    I installed the 10.5.6 Combo update. Sometimes things get "lost in the translation" when you use Software Update depending on your installation. Perhaps you can download 10.5.6 Combo from the website and install it from your desktop.

  • Problem with mail for exchange after update on E72...

    Hi everyone,
      I updated Nokia E-mail to ver 3.9 on E72. Now I am facing  a problem with mail for exchange. I have configured gmail on mail for exchange. I recieve a warning that "unable to sync contact administrator if problem persist". It started to pop up just after the update was over and is very frustrating. Even previously i used to recieve mails instantly but now it generally takes half an hour for me to recieve them. I deleted and created mail for exchange several times but to no avail.
    Also i am not able to automatically recieve mails other emails which i have configured. every time I have to manually download them everytime.
    Can anybody suggest a way out.
    Thanks
    Anil

    It could be a problem if you're using your network's connections...
    I was on a Pay & Go tariff with o2 some time ago, and needed secure connections for various things, o2 told me they didn't provide secure connections on Pay & Go tariffs...
    Could be worth checking with them to make sure it's supported.
    Nokia History: 3110, 5110, 7110, 7110, 3510i, 6210, 6310i, 5210, 6100, 6610, 7250, 7250i, 6650, 6230, 6230i, 6260, N70, N70, 5300, N95, N95, E71, E72
    Android History: HTC Desire, SE Xperia Arc, HTC Sensation, Sensation XE, One X+, Google Nexus 5

  • I am having a problem with mail. In my junk mail folder I have two messages which I drag to trash and empty. Within a few minutes the messages are back in junk mail folder

    I am having a problem with mail.  I am attempting to trash junk mail. Each time I do this and a while later I find the junk mail has not been discarded and is back in junk mil folder.

    Hi tony paine,
    Welcome to the Support Communities!
    The article below may be able to help you with this.
    Click on the link to see more details and screenshots. 
    iCloud: Keeping the Junk folder consistent between iCloud Mail and OS X Mail
    http://support.apple.com/kb/HT4911
    Cheers,
    - Judy

  • I have a problem with Mail on my Macbook Pro. It is configurated with a gmail account, and now I can't access the mail. Is it possible to reboot the account or..? Please help:)

    I have a problem with Mail on my Macbook Pro. It is configurated with a gmail account, and now I can't access the mail. Is it possible to reboot the account or..? Please help:)

    The question mark means the computer cannot find a bootable volumes so can;t do anything, That, combined with annoying sounds, strongly suggests a failed hard drive.
    You can ask a "genius" at an Apple Rtail Store to test it but I'm pretty sure the drive is kaput. I'm hoping you had your data backed up.

  • Having downloaded and installed the latest Maverick Ios I now have a problem with mail.All my mailboxes were in alphabetical order now they are arrange randomly under my mail account, sync does not rearrange them whilst the order in the ISP account is in

    I have downloaded Maverick 10.9 and installed , now my mailboxes in mail are randomly arranged as opossed to being in alphebetical order from A at the top to Z at the bottom how do you rearrenge the mailboxes in an alphbetical order.
    Sync with my provider Gmail does not rearrange them on my Imac

    Thanks for that .
    My actual problem I may not have made very clear - sorry.
    i.e.
    [email protected]
    AA insurance
    Xero
    apple
    building
    insurance
    etc.
    Shows the way the mailboxes are listed in the mail program under any particular provider, in my case I have three mail provider accounts with mail moved from the inbox to the appropraite mailbox eg [email protected] , Xero - where the incomeing mail is filed.
    My problem is to arrange these mailboxes/folders in an alphabetical order under the [email protected] account

  • Since installing mountain lion i have a problem with mail. when i delete a message close  and open mail the message has come back. please help!

    Since installing Mountain Lion i have a problem with Mail. I delete a number of messages from the same person but keep the newest message in my Inbox. I actually delete them from the Trash. The next time i open Mail the deleted messages are back again. Can anybody please help as this is getting annoying. Thanks in Anticipation.

    Problems such as yours are sometimes caused by files that should belong to you but are locked or have wrong permissions. This procedure will check for such files. It makes no changes and therefore will not, in itself, solve your problem.
    First, empty the Trash.
    Triple-click the line below to select it, then copy the selected text to the Clipboard (command-C):
    find ~ $TMPDIR.. \( -flags +sappnd,schg,uappnd,uchg -o ! -user $UID -o ! -perm -600 -o -acl \) 2> /dev/null | wc -l
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). The command may take a noticeable amount of time to run. Wait for a new line ending in a dollar sign (“$”) to appear.
    The output of this command, on a line directly below what you entered, will be a number such as "41." Please post it in a reply.

Maybe you are looking for