Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

To use:


You can also use a file for the body:

/bin/mail -s "$SUBJECT" "$RECIPIENT_ADDRESS" < /tmp/message.txt
share|improve this answer
It says missing postfix/ file , how can i download that file – John Apr 27 '10 at 6:15
When you installed mailx it should have run through the install screens for postfix. Did it ask you which type of install, and for the mail name and relay host? And when does it give you the error, when you run /bin/mail or when you tried to install? – nedm Apr 27 '10 at 6:21
it didn't ask me anything, how can uninstall it and do that again – John Apr 27 '10 at 6:28
If you have postfix set up as part of another install it sounds like it may not be configured correctly. Try "sudo dpkg-reconfigure postfix" and then "sudo /etc/init.d/postfix reload" – nedm Apr 27 '10 at 6:28
If postfix isn't installed, then "sudo apt-get remove mailx" and then "sudo apt-get install mailx" and it should install postfix with the mailx package. – nedm Apr 27 '10 at 6:31

The 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.

share|improve this answer
And far easier/quicker to get up and running than postfix. – hometoast Apr 29 '10 at 16:13

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.


Man page:

share|improve this answer

Install postfix and mailx

apt-get install postfix mailx

share|improve this answer

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

The option 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"

Hope this helps.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.