autoresponder script mail rules. Not sending

I am new to applescript, but have set up the following script paired with a mail rule. Its working with exception of the responding mail just opening but not going out, unless I click send manually.

tell application “Mail”
set theSignatureName to “MySignature”
set theMessages to the selected messages of the front message viewer
set theMessage to first item of theMessages
set theOutgoingMessage to reply theMessage with opening window
set message signature of theOutgoingMessage to signature theSignatureName
set sender of theOutgoingMessage to “MyAccount”
send
end tell

What am I doing wrong?

Try to use : send theOutgoingMessage

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mardi 31 janvier 2017 15:21:17

Tried, but still the same. Opens the mail ready to send, but not sending.

Here it works as long as I don’t try to insert a signature but in this case I get the error message:
error “Erreur dans Mail : Le gestionnaire AppleEvent a échoué.” number -10000

As I am curious, I searched a bit and found this thread about a bug in Sierra breaking the use of signatures.

http://macscripter.net/viewtopic.php?pid=188442

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mercredi 1 février 2017 10:55:38

I don’t seem to have any issues with the signature. My html signature opens up perfectly in the outgoing message. It simply doesn’t send.

May you tell which operating system you are running ?

What I described is what I get under Sierra 10.12.3.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mercredi 1 février 2017 12:03:37

Sierra 10.12.2

Thanks.

Here, using 10.12.3, the script :

tell application "Mail"
	set theSignatureName to "MySignature"
	set theMessages to the selected messages of the front message viewer
	set theMessage to first item of theMessages
	set theOutgoingMessage to reply theMessage with opening window
	--set message signature of theOutgoingMessage to signature theSignatureName # DISABLED because it issue an error
	set sender of theOutgoingMessage to "MyAccount"
	send theOutgoingMessage # EDITED
end tell

I get this events log :

tell application "Mail"
	get selected messages of message viewer 1
	reply message id 229382 of mailbox "INBOX" of account id "85F0K6YD-G883-4S03-9267-52P7TTGYY278" with opening window
	set sender of outgoing message id 1 to "MyAccount"
	send outgoing message id 1
end tell
Résultat :
true

Above, the account id is deliberately modified.
The signature attached to myAccount is automatically inserted in the message although it’s not asked by the script.

When I run the script posted in the thread which I reported, I get :

Default;missing value;missing value

The script can’t identify the signatures.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) mercredi 1 février 2017 12:35:16

Finally got it working with this one:

Thanks for all the help!

using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
repeat with eachMessage in theMessages
set theName to extract name from sender of eachMessage
if exists reply to of eachMessage then
set theAddress to reply to of eachMessage
else
set theAddress to extract address from sender of eachMessage
end if
set customHTML to “”
set newMessage to make new outgoing message with properties {html content:customHTML}
tell newMessage
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
set visible to false
set subject to "Re: " & subject of eachMessage
set sender of newMessage to “admin@x.es”
end tell
send newMessage
tell eachMessage
set was replied to to true
end tell
end repeat
end tell
end perform mail action with messages
end using terms from

Thanks for the feedback.

I note that you are no longer triggering the signature object.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 3 février 2017 12:09:55

No, I have set it as default signature for the sending account.

And it’s why the script works now.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 3 février 2017 12:38:02

I think because he wrapped the mail rule handler around it which he doesn’t in earlier versions?

Now I need this script modified to search for email address within the text and reply to that email. Any help? :slight_smile:

Hello DJ

When I tested it, the code wasn’t wrapped in the mail rule handler.
Everything worked except the instruction trying to use a given rule.
More, the problem with the named feature is described elsewhere.

Maybe, but I’m skeptical, wrapping the code in the handler was intercepting the error without reporting it.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 3 février 2017 15:19:23

The Mail’s Applescript dictionary states:
[format]message‚n : An email message
elements
contains bcc recipients, cc recipients, recipients, to recipients, headers, mail attachments; contained by message viewers, mailboxes.
properties
id (integer, r/o) : The unique identifier of the message.
all headers (text, r/o) : All the headers of the message
background color (blue/Œgray/Œgreen/Œnone/Œorange/Œother/Œpurple/Œred/Œyellow) : The background color of the message
mailbox (mailbox) : The mailbox in which this message is filed
content (rich text, r/o) : Contents of an email message
date received (date, r/o) : The date a message was received
date sent (date, r/o) : The date a message was sent
deleted status (boolean) : Indicates whether the message is deleted or not
flagged status (boolean) : Indicates whether the message is flagged or not
flag index (integer) : The flag on the message, or -1 if the message is not flagged
junk mail status (boolean) : Indicates whether the message has been marked junk or evaluated to be junk by the junk mail filter.
read status (boolean) : Indicates whether the message is read or not
message id (text, r/o) : The unique message ID string
source (text, r/o) : Raw source of the message
reply to (text, r/o) : The address that replies should be sent to
message size (integer, r/o) : The size (in bytes) of a message
sender (text, r/o) : The sender of the message
subject (text, r/o) : The subject of the message
was forwarded (boolean, r/o) : Indicates whether the message was forwarded or not
was redirected (boolean, r/o) : Indicates whether the message was redirected or not
was replied to (boolean, r/o) : Indicates whether the message was replied to or not
responds to[/format]

So you must ask the message for its reply to property.

tell application "Mail"
	activate
	set aMessage to item 1 of (get selection)
	reply to of aMessage
	--> "Télérama Soirée <soiree@redaction.telerama.fr>"
end tell

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 3 février 2017 15:30:20