I have installed ubuntu on my server. I want the cronjobs to send me emails for output.
How can i send emails from terminal . which thing i have to install and how will i put smtp or pop setting in that program
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
I believe mailx is what you're looking for.
sudo apt-get install bsd-mailx
This will also install postfix at a minimum, and will give you a few options to set postfix up. If you have an SMTP server on your LAN, choose 'satellite system', then enter the mail domain name, and lastly the IP address of your SMTP server.
echo $MESSAGE_BODY | /bin/mail -s "$SUBJECT" "$RECIPIENT_ADDRESS"
You can also use a file for the body:
/bin/mail -s "$SUBJECT" "$RECIPIENT_ADDRESS" < /tmp/message.txt
ssmtp package is popular for an easily way to send email from an ubuntu box. Here is a tutorial to set it up to use gmail.
If you do not wish to mess around with configuring Postfix (which can be an awful pain) checkout the heirloom-mailx package (sudo apt-get install heirloom-mailx).
This is an alternative version of the mail command that lets you specify an external SMTP server. For simple cron scripts it is ideal.
I use a standard setup in my shop, and I find mailutils package perfect, for doing things like sending auto emails from cronjobs etc. Very simple to set up through a ncurses config helper.
sudo aptitude install mailutils sudo dpkg-reconfigure exim4-config
internet site; mail is sent and received directly using SMTP works best for me (as I want to send for the most part). You can also set your root forward address through this config.
You can then send emails using the command line (someone above gave examples) but I use:
mail -s "AVScan completed on HOSTNAME" email@example.com
Hope this helps.
Latest installation i did was on Ubuntu 11.10 with command:
sudo apt-get install postfix mailutils
And if you want to read more on postfix, how it works and how to test it try : PostfixBasicSetupHowto
You could then use the