Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

6 Answers

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
add comment

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:

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
share|improve this answer
    
It says missing postfix/main.cf 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
show 1 more comment

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.

Homepage: http://heirloom.sourceforge.net/mailx.html

Man page: http://heirloom.sourceforge.net/mailx/mailx.1.html

share|improve this answer
add comment

Install postfix and mailx

apt-get install postfix mailx

share|improve this answer
add comment

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" avnotifications@somedomain.com

Hope this helps.

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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