Can't get Mail to attach specific file.

I am writing a script that will create standard emails. I would like the email to have an attachment. I cannot get the script to attach the file automatically. Any help with what I am doing wrong would be appreciated.

Here is the part of the script I am having trouble with:

if theSelection is equal to {"Building Roofing Solutions"} then tell application "Mail" activate set this_message to make new outgoing message with properties {visible:true, subject:"Test Subject", content:"Test Content"} tell this_message make new to recipient at end of to recipients with properties {address:this_email as text} make new attachment with properties {file name:"Macintosh HD:Sampe.pdf"} at after the last paragraph end tell end tell end if

Hi,

the syntax for make new attachment is a little different

if theSelection is equal to {"Building Roofing Solutions"} then
	tell application "Mail"
		activate
		set this_message to make new outgoing message with properties {visible:true, subject:"Test Subject", content:"Test Content"}
		tell this_message
			make new to recipient at end of to recipients with properties {address:this_email as text}
			tell content to make new attachment with properties {file name:"Macintosh HD:Sampe.pdf" as alias} at after the last paragraph
		end tell
	end tell
end if

Also, depending on the rest of the script, you might need to change

tell content to make new attachment with properties {file name:"Macintosh HD:Sampe.pdf" } at after the last paragraph

to

tell content to make new attachment with properties {file name:"Macintosh HD:Sampe.pdf" as alias} at after the last paragraph

StefanK,

I change the code and I am no longer getting an error message, but the file is still not attaching.

The email address, subject and contect show up but no attachment. I verified that the file path is correct. I have a file called Sampe.pdf on the root level of my drive (named Macintosh HD)

I even pulled the code out of the rest of the script and still no joy.

capitalj,

Thanks the as alias code was the rest of the puzzle. Thanks to both Stefank and capitalj.

Did you try my suggestion ? (post #3)

EDIT- oops, we posted at the same time.

sorry, I forgot “as alias” :slight_smile: