#!/bin/bash # Send an email via Mail.app # Usage: mail-send.sh "to@email.com" "Subject" "Body" [from-account] [attachment] TO="${1:-}" SUBJECT="${2:-}" BODY="${3:-}" FROM_ACCOUNT="${4:-}" ATTACHMENT="${5:-}" if [ -z "$TO" ] || [ -z "$SUBJECT" ] || [ -z "$BODY" ]; then echo "Usage: mail-send.sh \"to@email.com\" \"Subject\" \"Body\" [from-account] [attachment]" echo " All three arguments (to, subject, body) are required." exit 1 fi # Escape quotes in body and trim whitespace BODY_ESCAPED=$(printf '%s' "$BODY" | sed 's/"/\\"/g') SUBJECT_ESCAPED=$(printf '%s' "$SUBJECT" | sed 's/"/\\"/g') if [ -n "$FROM_ACCOUNT" ] && [ -n "$ATTACHMENT" ]; then osascript <