Linux command line tools to send mails are very handy for sending mails from bash scripts. As an example you can send daily php error logs (with some cap) to your email. Here are some ways you can send mail using Linux mail utility (mailutils package) on Ubuntu Linux.
In case you dont have mailutils installed, install it using apt-get.
$ sudo apt-get install mailutils $ dpkg -l mailutils Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-===========================-==================-==================-============================================================ ii mailutils 1:2.99.98-1.1 amd64 GNU mailutils utilities for handling mail
Sending mail with specific “from email” and subject
To send email with a specific subject and piping mail body content:
$ echo "hello" | mail -aFrom:email@example.com -s test firstname.lastname@example.org,email@example.com
Note that -a is used to attach headers and can be repeated multiple times. You can also attach CC: and other headers using it. To pick mail body from a file, use the following command:
$ mail -aFrom:firstname.lastname@example.org -s test email@example.com,firstname.lastname@example.org < /path/to/mail/content/file
To send attachment we'll use -A option.
$ echo "hello" | mail -aFrom:email@example.com -s test firstname.lastname@example.org -A attachmentfilename.txt
Notes on spam
These mails (probably initially) may end up in user's spam folder if the machine has not implemented Sender policy framework. If you have access to receiver's email, you can mark them not spam and later these emails will have higher chances of hitting the inbox.