4

I want to create a local mail account suitable for apt-listchanges. In other words, local services will send mail to local@localhost (?) and I should be able to check that mailbox using a regular mail client (Thunderbird, Geany...)

This would preferably be a "system" account rather than a "user" account, but if userland apps can't access that, a "user" account will do.

2 Answers 2

3

On a Debian-based system you should already have exim4 which provides the sendmail utility. Configure it as follows:

1. Confirm FQDN

exim4 requires a "fully qualified" domain name for your local machine, which just means it needs a dot in it. Confirm this with the following:

$ hostname
$ hostname --fqdn

These will return your machine name and your FQDN. By default your FQDN is exactly the same as your machine name and does not contain a dot, and you need to change it.

(If it is different and contains a dot, skip step 2.)

2. Modify hosts file

We will now set your FQDN. To do this modify your hosts file:

sudo nano /etc/hosts

You should see the following lines in the file (gaps are tabs):

127.0.0.1    localhost
127.0.1.1    HOSTNAME

change this to...

127.0.0.1    localhost
127.0.1.1    mail.localhost    HOSTNAME

...then save and exit. Repeat step one to confirm that your hostname remains the same, and your FQDN has been updated.

3. Configure exim4

Configure exim4 as follows:

sudo dpkg-reconfigure exim4-config

In the questions that follow select the following options (and otherwise select the defaults):

  • "local delivery only; not on a network"
  • System mail name: "mail.localhost"
  • Other destinations for which mail is accepted: "mail.localhost"
  • Keep number of DNS queries minimal? Yes
  • Delivery method: mbox format in /var/mail
  • Where to send root and postmaster mail: USERNAME@localhost
    • Now system messages will be sent to your user account and you don't need special permissions to access them

4. Test

To test, you can send a local email with mail USERNAME@localhost. Fill in the prompts as follows

$ mail USERNAME@localhost
Cc: <leave blank, hit enter>
Subject: test subject
test body <hit enter>
<hit Ctrl-D>

You can confirm the message has been received by typing mail. Hit Q to quit the text-based mail client.

5. Configure MUA GUI

Now configure your preferred GUI client for mbox access, and check that your test message also appears in your inbox there.

2
  • I wonder whether this works for sending mails to the root user as well? Currently I can't send mail from a user other than the root user to the root user (but it works for another purpose I mainly needed it for).
    – aderchox
    Jun 19, 2020 at 20:35
  • Note that a default desktop install of Ubuntu 18.04 does not come with exim installed.
    – MestreLion
    Mar 31, 2021 at 21:31
2

I'm not sure I understand what you mean by system and user accounts but if you're asking how to handle local e-mail on Linux it's quite simple. I don't use Ubuntu on the daily basis but I've just run the following in the virtual machine:

$ sudo apt-get install sendmail

sendmail is the name of the SMTP server that will deliver e-mails.

$ sudo apt-get install mutt

mutt is the name of the Mail User Agent that we'll use to read mail.

Make sure that sendmail is running:

$ ps aux | grep '[s]endmail'
root     31687  0.0  0.1 108964  5408 ?        Ss   19:24   0:00 sendmail: MTA: accepting connections

Send a test e-mail to yourself:

$ sendmail -i $(whoami) <<MAIL_END
> Subject: test e-mail
>
> HELLO
> MAIL_END

Note that after pressing Enter you get:

You have new mail in /var/mail/<USERNAME>

Use mutt to read mail, for example:

$ mutt -f /var/mail/ja

Actually, when using mutt you don't even have to use -f:

$ mutt

is enough as mutt will try to open $MAIL. In Ubuntu it's defined by default:

$ echo $MAIL
/var/mail/ja

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .