User Tools

Site Tools


how_to_make_the_mail_command_work

Command line email

The 'mail' command is used to check system-local email (not Internet email) and to send email from the command line. It can be used in scripts to send status messages and alerts to your email address. For example, you could send yourself email with this one-liner:

echo MESSAGE BODY | mail MYSELF@ncsu.edu -s "SUBJECT LINE"

Unfortunately, though, it's not configured to work with Internet email out-of-box on many Linux systems. Here are the quick steps to enabling it:

Ubuntu

On Ubuntu 7.04 and some later versions (not sure up to what), do apt-get install mailx. Starting around 10.04, the package name changes, so do apt-get install mailutils.

Next, configure for Internet sending:

$ sudo dpkg-reconfigure exim4-config

In the menu, select:

  • General type of mail configuration: internet site; mail is sent and received directly using SMTP
  • System mail name: Accept the default, which should be the FQDN (e.g. davros.csc.ncsu.edu)
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 (default)
  • Other destinations for which mail is accepted: (either blank or the FQDN)
  • Use the defaults for the rest of the questions

Note that because the mail server is set to listen only on 127.0.0.1, this will not open the SMTP server up to internet traffic (and the security concerns that brings).

CentOS / Fedora / RHEL

This has been tested on CentOS 5.3, but will likely work elsewhere. We'll just install postfix and a little admin tool to enable it:

$ sudo yum install postfix system-switch-mail
...
Is this ok [y/N]: y
...

Then enable postfix:

$ sudo system-switch-mail

Select postfix from the menu.

Note that because the mail server is set to listen only on 127.0.0.1 by default, this will not open the SMTP server up to internet traffic (and the security concerns that brings).

Troubleshooting

If your email doesn't go through, run 'mail' alone to check your local Unix-type mail. If there are messages, view them with 'p' and observe the error message. If there's nothing, check the log files in /var/log.

how_to_make_the_mail_command_work.txt · Last modified: 2010/12/03 23:25 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki