Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Send one email to the senders of multiple Mail messages Apps
As an editor for a school publication, I have a folder in Mail set for content that other students submit. Recently I found myself needing to send one email to every submitter (nearly 150 emails in all!), yet I found that I could not simply do a Command-A and hit Reply.

After a bit of AppleScript work, I came up with this script:
set thesenders to {}
set thesenderstext to ""
tell application "Mail"
  set themessage to the selection
  repeat with i from 1 to the number of items in themessage
    set thesender to (the sender of (item i of themessage))
    if thesenders does not contain thesender then
      set thesenders to thesenders & {thesender}
    end if
  end repeat
  set AppleScript's text item delimiters to ", "
  set thesenderstext to thesenders as text
  set the clipboard to thesenderstext
end tell
It creates a comma-separated list of the senders of the selected messages, and then sets the clipboard to said list (it also removes duplicates). Select a bunch of messages in Mail, run the script, then paste the clipboard's contents into a new message.

[robg adds: This worked as described in my testing.]
    •    
  • Currently 1.75 / 5
  You rated: 2 / 5 (4 votes cast)
 
[8,621 views]  

Send one email to the senders of multiple Mail messages | 8 comments | Create New Account
Click here to return to the 'Send one email to the senders of multiple Mail messages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Send one email to the senders of multiple Mail messages
Authored by: pmbuko on May 24, '07 10:03:54AM
This is a great hint, but the creation of a new email to the recipients can be scripted, as well. Just replace the last line ("set the clipboard to thesenderstext") with the following:
set newMessage to make new outgoing message
tell newMessage
     set visible to true
     make new to recipient with properties {address:thesenderstext}
end tell
activate


[ Reply to This | # ]
Send one email to the senders of multiple Mail messages
Authored by: osxpounder on May 24, '07 11:06:36AM

Brilliant, both tip and first comment! Thanks!

I took pmbuko's suggested line and simply added it after the "set clipboard" line, so that the script also puts the addresses on the clipboard. Since I use a clipboard tool [I like Butler and iSnip, both for different reasons], I don't mind loading those addresses to the clipboard. I just wanted to see if it would do it. Great!



[ Reply to This | # ]
Send one email to the senders of multiple Mail messages
Authored by: mattharris5 on May 24, '07 12:05:27PM
I had a problem with multiple senders being grouped together with only one email address. I guess Mail thought that the comma separated list I was giving it was one long name. To fix it, I added extract address from to line 6 of the script:
set thesender to (extract address from (the sender of (item i of themessage)))
and it works perfectly now.

[ Reply to This | # ]
Send one email to the senders of multiple Mail messages
Authored by: osxpounder on May 25, '07 01:19:33PM

Thanks so much for this improvement! I only just now realized, when you mentioned problems, that the original script failed when I replied to GroupWise email users. They received nothing, but I received no error message, in my single test, so I didn't know they received nothing until I tested your modification on my own GroupWise account.

With your change, I received the message at my GroupWise email account. Since I wanted to use this for work, that's essential. Thanks again for sharing that.



[ Reply to This | # ]
Send one email to the senders of multiple Mail messages
Authored by: morespace54 on May 28, '07 08:52:39AM

That's all fine and working great! Thanks...

What I would really like, would be the same script but with all the recipents to appear in the "Bcc" field (instead of the "To"). This way, each recipient would not have the list of all the other 150 recipents addresses... I'm new to AppleScript but I've managed to to change the line "make new to recipient with properties" with "make new bcc recipient with properties" but it's seems I can't figure out how to put myself as the default "To" (even hard coded in the AS, but a pop-up or a list of accounts would be even better)...

Maybe one day, I'll figure it out...



[ Reply to This | # ]
Send one email to the senders of multiple Mail messages
Authored by: morespace54 on May 31, '07 01:38:50PM

Okay here is my flaky solution:


<code>
set thesenders to {}
set thesenderstext to ""
--
set theName to ""
--
set theSubject to ""

set my_result to display dialog
"Subject:" default answer theSubject
buttons {"Cancel", "Continue"} default button 2
set theSubject to the text returned of my_result
--
set myaddress to ""

tell application "Mail"
set listOfSenders to {}
set everyAccount to every account
repeat with eachAccount in everyAccount
set everyEmailAddress to email addresses of eachAccount
if (everyEmailAddress is not equal to missing value) then
repeat with eachEmailAddress in everyEmailAddress
set listOfSenders to listOfSenders & {(full name of eachAccount & " <" & eachEmailAddress & ">") as string}
end repeat
end if
end repeat
end tell

set my_result to choose from list listOfSenders with prompt
"Which account would you like to send this message to?" without multiple selections allowed
if my_result is not equal to false then
set myaddress to item 1 of my_result
end if
--
set myAccount to ""

tell application "Mail"
set listOfSenders to {}
set everyAccount to every account
repeat with eachAccount in everyAccount
set everyEmailAddress to email addresses of eachAccount
if (everyEmailAddress is not equal to missing value) then
repeat with eachEmailAddress in everyEmailAddress
set listOfSenders to listOfSenders & {(full name of eachAccount & " <" & eachEmailAddress & ">") as string}
end repeat
end if
end repeat
end tell

set my_result to choose from list listOfSenders with prompt
"Which account would you like to send this message from?" without multiple selections allowed
if my_result is not equal to false then
set myAccount to item 1 of my_result
end if
--

tell application "Mail"
set themessage to the selection
repeat with i from 1 to the number of items in themessage

set thesender to (extract address from (the sender of (item i of themessage)))

if thesenders does not contain thesender then
set thesenders to thesenders & {thesender}
end if
end repeat
set AppleScript's text item delimiters to ", "
set thesenderstext to thesenders as text

set newMessage to make new outgoing message with properties {sender:myAccount, subject:theSubject}
tell newMessage
set visible to true
make new bcc recipient with properties {address:thesenderstext}
make new to recipient at end of to recipients with properties {name:theName, address:myaddress}
end tell
activate

end tell

</code>

Now it needs a little tightning... ;)



[ Reply to This | # ]
AppleScript's text item delimiters
Authored by: airdrummer on May 29, '07 09:04:23AM

u 4got 2 reset afterwards:

set AppleScript's text item delimiters to ", "
set thesenderstext to thesenders as text
+ set AppleScript's text item delimiters to ""



[ Reply to This | # ]
AppleScript's text item delimiters
Authored by: osxpounder on May 31, '07 12:45:45PM

airdrummer, can you explain more, please? Why would we want to do this? Does not resetting cause problems with other scripts, or .... what?



[ Reply to This | # ]