Sending Email from the Command Line with mutt
If you prefer using mutt
as your command line email
tool, then here are a couple of examples of using mutt
to
send emails which can be automated quite easily to use in scripts.
Sending a file attachment (-a) and an empty message body:
$ mutt -s "System Logs" -a /var/log/somelog.log -- username@example.com < /dev/null
Sending a message body using redirection:
$ mutt -s "Email Subject" username@example.com < email.html
Sending a file attachment along with a message body:
$ echo $message | mutt -s "Email Subject" -a attachment.txt -- username@example.com
Sending Email from the Command Line
mutt Examples
Sending just a file attachment (-a) and an empty message body:
$ mutt -s "System logs" -a /opt/backup.sql -- user@example.com < /dev/null
Sending a message body using redirection:
$ mutt -s "Email subject" test@example.com < email.html
Sending a file attachment along with a message body:
$ echo $message | mutt -s "Subject" -a attachment.txt -- me@myemail.com
mailx Example:
$ echo "message body" | mail -s "subject" test@example.com