Friday, March 4, 2011

Ubuntu: Sending command line mail

SkyHi @ Friday, March 04, 2011
user@Januty:~/BashTuts$ mail -s "user1" user1@gmail.com
The program 'mail' can be found in the following packages:
 * heirloom-mailx
 * mailutils
Try: sudo apt-get install

user@Januty:~/BashTuts$ sudo apt-get install mailutils
didn't configure postfix


Mar  4 15:26:22 Januty postfix/error[10911]: 8226929760: to=, relay=none, delay=2.1, delays=2/0.01/0/0.09, dsn=5.0.0, status=bounced (gmail.com)

ERROR:
fatal: open /etc/postfix/main.cf: No such file or directory

Solution:
user@Januty:~/BashTuts$ sudo dpkg-reconfigure postfix





Please select the mail server configuration type that best meets your needs.
            â
            â  No configuration:
            â   Should be chosen to leave the current configuration unchanged.
            â  Internet site:
            â   Mail is sent and received directly using SMTP.
            â  Internet with smarthost:
            â   Mail is received directly using SMTP or by running a utility such
            â   as fetchmail. Outgoing mail is sent using a smarthost.
            â  Satellite system:
            â   All mail is sent to another machine, called a 'smarthost', for delivery.
            â
            â          



=======================================================================
Ubuntu: Sending command line mail
I needed to send email from the command line, specifically for cron jobs, and there are many programs which can do this. I'm going to use the gnu mailutils package so first off let's install the mailutils package:
# apt-get install mailutils

This will add a few extra packages, then bring us up into an exim4 configuration screen. My systems are behind a dsl router, and I'm not going to route the mail through any relay host, I just want everything sent direct (for some sendmail agents this might cause problems, but you'll have to look at your logfiles). In the exim4 config screen I pick "internet site... mail is sent and receieved directly using SMTP". On edgy you might have to answer a few more questions, but I had to run a dpkg-reconfigure.

At this point we have exim4 listening on port 25 and I don't need that, so I need to stop the daemon and remove the startup links:
# /etc/init.d/exim4 stop
# update-rc.d -f exim4 remove


The update-rc.d command removes inits startup/shutdown links, but unfortunately if the exim4 packages get updated the links will be back so we need to run that command again.

Now lets try sending a test mail:
# echo testing | mail -s Bla myemail@somewhere.com

and take a look at /var/log/exim4/mainlog. You should be good to go!

REFERENCES
http://www.quietearth.us/articles/2006/09/25/Ubuntu-Sending-command-line-mail