Hi,
I found this script on macOSXHints.com that allow you to send back a receipt, if asked, in the application mail.
It works in Tiger but has no effect in Leopard.
Anyone knows what is wrong with it ?
using terms from application "Mail"
on perform mail action with messages selectedMsgs
repeat with msg in selectedMsgs
set theSubject to subject of msg
set theSender to extract name from sender of msg
set theAddress to extract address from sender of msg
set theDate to date sent of msg
tell application "Mail"
set nowDate to current date
set theBody to "Your message" & return & return & " Re: " & theSubject & return & " Sent: " & theDate & return & return & "was received and read " & nowDate & ". Thank you." & return
set newMessage to make new outgoing message with properties {subject:"Return Receipt: " & theSubject, content:theBody & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
end tell
end tell
end repeat
end perform mail action with messages
end using terms from
PS : It is a script that is run in a mail rule, when “Disposition-Notification-To” contains “@”
Hi,
for any reason creating (and sending) an outgoing mail in a rule is broken in Leopard
True.
I just did a test and those rules are indeed no more working in Leopard.
This is quite à big bug, isn’t it ?
So the problem seems to be with mail, not with the script, right ?
Right, but the script works called from the script menu without the action handler
Well not for me…
Could you describe what you do to make it work, “step by step” ?
BTW : concerning the mail rules, is even worse : when I use a rule to answer messages in certain conditions, it seems like nothing happens but the mails are actually sent back with the choosen text, you just don’t know it. I know it because I received an answer to some of the mails I had sent to myself.o
You have to define selectedMsgs with the current selected mails
and add a Mail tell block
-- using terms from application "Mail"
-- on perform mail action with messages selectedMsgs
tell application "Mail"
set selectedMsgs to selection
repeat with msg in selectedMsgs
set theSubject to subject of msg
set theSender to extract name from sender of msg
set theAddress to extract address from sender of msg
set theDate to date sent of msg
-- tell application "Mail"
set nowDate to current date
set theBody to "Your message" & return & return & " Re: " & theSubject & return & " Sent: " & theDate & return & return & "was received and read " & nowDate & ". Thank you." & return
set newMessage to make new outgoing message with properties {subject:"Return Receipt: " & theSubject, content:theBody & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
end tell
-- end tell
end repeat
end tell
-- end perform mail action with messages
-- end using terms from
It works indeed.
What I could do now is set a rule that gives a specific color to any mail that ask a receipt (cfr 1st post) and each time I receive a mail that has that color, I should know it asks a receipt and I can use your script from the script menu if I want to.
That makes an excellent work around.
Thanks for your modified script.
another workaround:
Create a script and save it as application (applet), name it e.g. MailSender
with this code:
on send_mail(theSubject, theContent, myAccount, theSender, theAddress)
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theContent & return & return}
tell newMessage
set sender to myAccount
make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
end tell
activate
send newMessage
end tell
end send_mail
then this modified rule script works,
the trick is to call a handler of an application
property myaccount : "John Doe <john@doe.com>"
using terms from application "Mail"
on perform mail action with messages selectedMsgs
repeat with msg in selectedMsgs
set theSubject to subject of msg
set theSender to extract name from sender of msg
set theAddress to extract address from sender of msg
set theDate to date sent of msg
set nowDate to (current date) as text
set theBody to "Your message" & return & return & " Re: " & theSubject & return & " Sent: " & theDate & return & return & "was received and read " & nowDate & ". Thank you." & return
tell application "MailSender"
launch
send_mail("Return Receipt" & theSubject, theBody, myaccount, theSender, theAddress)
end tell
end repeat
end perform mail action with messages
end using terms from