title: Sending emails with attachments through AppleScript
body: <p>So I wanted to be able to send an email with an attachment using applescript. 
  I have this teacher who regularly makes us do labs and requires us to send them via email, so I decided to combine hazel and applescript to make this easier. </p>
  
  <p>Basically when I export the document into a pdf in my folder, hazel detects it and sends it to another folder which then calls the script required to send the email with the attachment. Once that is done hazel puts the file back in the original folder and appends an _sent to the name so that it does not send it again. (The folder is always empty unless a file was just exported as a pdf)</p>
  
  <p>My problem is that the files aren't attached to the email. (And most of the time I get an error with my script saying it didn't run successfully, but this is not the point).</p>
  
  <p>I had the same problem using automator, files weren't attached. I tried several codes but always get the same problem. The email is sent with no files attached. Here is the code:</p>
  
  <pre><code>tell application "Finder"
  set folderPath to folder "Macintosh HD:Users:user_directory:Desktop:Send_Mail"
  set fileList to name of file 1 in folderPath
  end tell
  
  set theSubject to fileList
  set theBody to "Hello sir. Here is my " &amp; fileList
  set theAddress to "Some Email"
  set theAttachment to fileList
  set theSender to "Some Sender"
  
  tell application "Mail"
  set theNewMessage to make new outgoing message with properties {subject:theSubject,         content:theBody &amp; return &amp; return, visible:true}
      tell theNewMessage
      set visibile to true
      set sender to theSender
      make new to recipient at end of to recipients with properties {address:theAddress}
      try
          make new attachment with properties {file name:fileList} at after the last word of the last paragraph
          set message_attachment to 0
          log "message_attachment = " &amp; message_attachment
      on error
          set message_attachment to 1
      end try
      #tell content
      #   make new attachment with properties {file name:theAttachment, path:fileList}
  
      #end tell
      #send
      end tell
  end tell
  </code></pre>
  
  <p>the Only message that I get in the event log is "missing value". I don't understand what could be missing though. </p>