/home/alex/dev/sendmail.applescript (1)

From RaySoft
#!/usr/bin/osascript
-- -----------------------------------------------------------------------------
-- sendmail.applescript
-- ====================
--
-- Scope     macOS
-- Copyright (C) 2022 by RaySoft, Zurich, Switzerland
-- License   GNU General Public License (GPL) 2.0
--           https://www.gnu.org/licenses/gpl2.txt
--
-- -----------------------------------------------------------------------------
-- Command line input
-- - theRecipientName
-- - theRecipientAddress
-- - theSubject
-- - theContent
-- - theAttachment
-- -----------------------------------------------------------------------------

on run argv
  set theSender to "Alex the Lion <alex@raysoft.loc>"

  set theRecipientName to item 1 of argv
  set theRecipientAddress to item 2 of argv
  set theSubject to item 3 of argv
  set theContent to item 4 of argv
  set theAttachment to item 5 of argv as POSIX file


  tell application "Mail"
    activate

    set theMessage to make new outgoing message

    tell theMessage
      set visible to true
      set sender to theSender
      set subject to theSubject
      set content to theContent & return & return

      make new to recipient at end of to recipients ¬
        with properties {name:theRecipientName, address:theRecipientAddress}

      make new attachment at after the last paragraph ¬
        with properties {file name:theAttachment as alias}
    end tell
  end tell

end run

-- -----------------------------------------------------------------------------

Usage

osascript "${HOME}/dev/sendmail.applescript"