I remember Debian automatically sending mail to users (to report a failed sudo authentication attempt, for example). On Ubuntu is mail of some kind automatically set up? I created a cron job, and nothing is appearing in /var/spool/mail. If there's a standard/obvious way to set up mail in Ubuntu, what is it?
3 Answers
If you haven't done it yet you will need to install postfix (sudo apt-get install postfix
) or sSMTP (sudo apt-get install ssmtp
) to replicate the sendmail commands.
Ubuntu has a policy of not listening on any network ports (not running any network services) by default. That means no mailserver. So, yes, you need to install one if you want one.
You can set up postfix
to do local mail delivery only.
First,
sudo apt-get install postfix
After a moment, you'll be prompted to make some choices about how you want postfix installed. (If you make a mistake, you can get back here with sudo dpkg-reconfigure postfix
).
When prompted, choose "Local only" as your general configuration. When prompted for a system mail name, you can enter your machine's hostname (e.g. gribble
), its fully qualified domain name (e.g. gribble.strickland.us
), or localhost
. I suggest choosing the former or the latter.
With that done, do sudo postconf -e "home_mailbox = Maildir/"
to tell postfix where to place users' mail. This appends home_mailbox = Maildir/
to the end of /etc/postfix/main.cf
. sudo service postfix reload
to tell postfix to reload the configuration file.
Now you can install a mail client that understands how to read mail out of your maildir, such as mutt: sudo apt-get install mutt
To configure mutt, create a file ~/.muttrc
with something like the following in it:
set mbox_type=Maildir
set folder="~/Maildir"
set mask="!^\\.[^.]"
set mbox="~/Maildir"
set spoolfile="~/Maildir"
Run mutt
and it will probably complain about your maildir not being there. This is fine -- postfix will create it as soon as we get some email.
In mutt, press m to compose an email. At the bottom of the screen, you'll be prompted for a recipient (you should be able to type user@hostname or just a user name) and subject, then your editor will pop up so you can type an email. Write something, save, exit, and press y to send. The user you sent to should have a Maildir appear in their home directory -- they can then use mutt (after creating a similar .muttrc) to read it!