Applescript includes email attachment in Lion but not in Snow Leopard

:confused: I’ve been banging my head against this one for more than a day.

The following code sends an email message.

In Lion, the message and the attachment arrive at the destination.

In Snow Leopard, only the message arrives. The attachment does not.

No error is thrown. Can someone explain this behavior and how to make code that will work in both versions of the OS?


set theAttachment to "JJSLO:Jobs Direct:10000-10099:10010:10010 SLO sample Info:067 return 130520 10010.PDF"
set recipientAddress to "bc@xxxx.com"             --address redacted
set theSubject to "Test Subject"
set theContent to "The attached subject document has been saved."

tell application "Mail"
	set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
	tell theMessage
		make new to recipient at end of to recipients with properties {address:recipientAddress}
		make new attachment with properties {file name:theAttachment} at after the last paragraph
	end tell
	send theMessage
end tell

Model: MacBookPro
AppleScript: 2.4.3
Browser: Safari 6.0.3
Operating System: Mac OS X (10.7)

Hi,

“last paragraph” belongs to the content of the message


tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph

I tried that variation a few moments before you replied.

I still get no attachment with Snow Leopard.

I also tried sending from two other accounts on two other Snow Leopard Macs, just to make sure I had not accidentally selected a test account with restrictions on sending attachments.


set theAttachment to "JJSLO:Jobs Direct:10000-10099:10010:10010 SLO sample Info:067 return 130520 10010.PDF"
set recipientAddress to "bc@xxxxx.com"
set theSubject to "Test Subject"
set theContent to "The attached subject document has been saved."

tell application "Mail"
	set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
	tell theMessage
		make new to recipient at end of to recipients with properties {address:recipientAddress}
		tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph
	end tell
send theMessage
end tell

:slight_smile:

I was able to get the script to work in Snow Leopard with the addition of “as alias” to the end of the first line.

One of the most frustrating things about AppleScript is that I can never find out whether a property is expected to be a string, an alias or some other class.

Thanks to StefanK because I found the “as alias” syntax in his post at
http://macscripter.net/viewtopic.php?id=30296


set theAttachment to "JJSLO:Jobs Direct:10000-10099:10010:10010 SLO sample Info:067 return 130520 10010.PDF" as  alias
set recipientAddress to "bc@xxxxx.com"
set theSubject to "Test Subject"
set theContent to "The attached subject document has been saved."

tell application "Mail"
   set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
   tell theMessage
       make new to recipient at end of to recipients with properties {address:recipientAddress}
       tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph
       --NOTE WELL:  the file name property in the above line MUST be an alias to work in Snow Leopard
   end tell
send theMessage
end tell