Shell script to send email [duplicate] Shell script to send email [duplicate] shell shell

Shell script to send email [duplicate]


Yes it works fine and is commonly used:

$ echo "hello world" | mail -s "a subject" someone@somewhere.com


Basically there's a program to accomplish that, called "mail". The subject of the email can be specified with a -s and a list of address with -t. You can write the text on your own with the echo command:

echo "This will go into the body of the mail." | mail -s "Hello world" you@youremail.com

or get it from other files too:

mail -s "Hello world" you@youremailid.com < /home/calvin/application.log

mail doesn't support the sending of attachments, but Mutt does:

echo "Sending an attachment." | mutt -a file.zip -s "attachment" target@email.com

Note that Mutt's much more complete than mail.You can find better explanation here

PS: thanks to @slhck who pointed out that my previous answer was awful. ;)


sendmail works for me on the mac (10.6.8)

echo "Hello" | sendmail -f my@email.com my@email.com