I have modified some text from the applescript archives archives to attach a file to an email. This works fine if the file path is hard coded into the script, although won't work if the filepath is a variable.
the two working and non-working examples are below.
Any help would be greatly appreciated.
NOT WORKING
set theSubject to "The subject text"
set theBody to "The text of the message"
set theDestinationEmail to "email@hidden"
set myfile to "wayne:Users:waynemelrose:Documents:file.txt"
tell application "Mail"
set the new_message to (make new outgoing message with properties {visible:true, subject:theSubject, sender:"email@hidden", body:theBody & return})
tell the new_message
make new to recipient at end of to recipients with properties {address:theDestinationEmail}
tell content
make new attachment with properties {file name:alias myfile} at after the last character
end tell
end tell
end tell
WORKING
set theSubject to "The subject text"
set theBody to "The text of the message"
set theDestinationEmail to "email@hidden"
tell application "Mail"
set the new_message to (make new outgoing message with properties {visible:true, subject:theSubject, sender:"email@hidden", body:theBody & return})
tell the new_message
make new to recipient at end of to recipients with properties {address:theDestinationEmail}
tell content
make new attachment with properties {file name:alias "wayne:Users:waynemelrose:Documents:file.txt"} at after the last character
end tell
end tell
end tell
-------------------------------------
Wayne Melrose