Apple Mail in El Capitan - delay needed for messages with attachments?

Hi,

I’m using the enclosed script for creating mail messages since OS X v10.6 without any problem. Within El Capitan (v10.11.3 on my MacBook Pro Retina 13", Early 2015, 2,7 GHz i5) all messages are sent without attachments. I found, that the script always sends the mail before the attachments were included.

A “delay 1” solves the problem on my mac, but I’m not sure if this will work on any machine. The enclosed script is ready to use, if you uncomment the “delay 1” you will see the problem: if the dialog appears the attachment isn’t included inside the mail! Also if you press “Cancel” (normally stops the script) the attachment appears inside the new message.

I’m not sure if it is a bug in El Capitan, isn’t it? If anyone has an hint to solve it, I’m interested in.

Rebewslin


set MailAttFile to choose file
--set MailAttFile to alias "Macintosh HD:Users:UserName:Desktop:myattachment.pdf"
set MailAttFileList to {MailAttFile}

tell application "Mail" to set MailReceiverListTo to {{name:"Mail 1", address:"mail.1@mymail.com"}, {name:"Mail 2", address:"mail.2@mymail.com"}}
tell application "Mail" to set MailReceiverListCC to {{name:"Mail 3", address:"mail.3@mymail.com"}}
set MailText to "This is my text."
set MailSubject to "Mailsubject"



CreateMail(MailSubject, MailReceiverListTo, MailReceiverListCC, MailText, MailAttFileList)



--create a new mail message and send it instandly
on CreateMail(MailSubject, MailReceiverListTo, MailReceiverListCC, MailText, MailAttFileList)
	tell application "Mail"
		
		set newmessage to make new outgoing message with properties {visible:true, subject:MailSubject, content:MailText}
		
		repeat with x from 1 to count of items of MailAttFileList
			tell newmessage to make new attachment with properties {file name:(item x of MailAttFileList) as alias} at after last paragraph
		end repeat
		
		repeat with y from 1 to count of items of MailReceiverListTo
			tell newmessage to make new to recipient at end of to recipients with properties item y of MailReceiverListTo
		end repeat
		
		repeat with z from 1 to count of items of MailReceiverListCC
			tell newmessage to make new cc recipient at end of cc recipients with properties item z of MailReceiverListCC
		end repeat
		
		delay 1 --<-- this delay is necessary since OS X 10.11, earlier versions works without it
		
		--"activate" and "display dialog" is only for testing, normally "CreateMail" transmits the newmessage instantly
		activate newmessage
		display dialog "Ready for transmit! " buttons {"Cancel", "Transmit"} cancel button "Cancel" default button "Transmit"
		
		send newmessage
	end tell
end CreateMail