Instantly share code, notes, and snippets.

What would you like to do?
Setup a Local Only Email Server (Linux, Unix, Mac)

Setup a Local Only Email Server (Linux, Unix, Mac)

1 - Point to your machine

Most of programs will not accept an email using just @localhost as domain. So, edit /etc/hosts file to make the domain point to your machine, including this content to the file:

2 - Install Postfix

Fedora/CentOS/RHEL: sudo yum install postfix

Ubuntu: sudo apt-get install postfix

MacOSX: Postfix is already installed by default.

3 - Configure Postfix to Local only

  • During postfix install process, the configure text dialog will display five options:

    General type of mail configuration: 
    No configuration
    Internet Site
    Internet with smarthost
    Satellite system
    Local only
  • Select "Local Only".

  • For the domain name, use the default suggested and finish the install.

4 - Configure a Catch-all Address

Enabling this, you can use any email address ending with "@localhost" or "".

Example: here, my unique account is But while testing systems, I can use any address like,, etc, because all will be redirected to

  • If not exists, create file /etc/postfix/virtual: sudo nano /etc/postfix/virtual
  • Add the following 2 lines content, replacing <your-user> with your Unix user account:
@localhost <your-user> <your-user>
  • Save and close the file.
  • Configure postifx to read this file:
    • Open /etc/postfix/ sudo nano /etc/postfix/
    • And check if this line is enabled, or add it if not exists: virtual_alias_maps = hash:/etc/postfix/virtual
  • Activate it: sudo postmap /etc/postfix/virtual
  • Reload postfix: sudo systemctl restart postfix
  • If you're under non systemd distro, like Ubuntu 14.04, service restart command probably is: sudo service postfix reload

5 - Install Thunderbird

Ubuntu: sudo apt-get install thunderbird

6 - Configure Thunderbird

  • Skip the welcome screen (click in the button to use existing accounts);
  • Click in the Settings button at top right (similar to Chrome settings) then click on Preferences > Account Settings
  • Under Account Actions choose "Add Other Account"
  • Select "Unix Mailspool (Movemail)"
  • Your account will be <your-user>@localhost (of course, replace <your-user> with your user account). Don't use <your-user>@(none), use <your-user>@localhost
  • Ingoing and Outgoing server will be: localhost
  • Restart (close and reopen) Thunderbird.

7 - Start your Mail Spool file

  • This step have two purposes: test your install and stop the Unable to locate mail spool file. message.
  • Using Thunderbird, send new email to <your-user>@localhost, replacing <your-user> with your user account
  • Click on "Get Mail"
  • Test catch-all: send new email to averagejoe@localhost
  • Click on "Get Mail" and you'll see the message at Inbox.

This comment has been minimized.

dipakpatilsymc commented Dec 30, 2015

Great article! Nice and easy.
Also its easy to configure multiple domains, I did step 1 and 4 for and worked like charm.
Now I receive emails directed to and in same inbox, which I wanted.


This comment has been minimized.

dangerouse commented Apr 27, 2016

How about using or and then you can skip editing the /etc/hosts file?


This comment has been minimized.

Feyisayo commented Jul 30, 2016

I followed these instructions and it worked like a charm

Thanks a lot


This comment has been minimized.

bpcrao commented Nov 6, 2016

Helpful, thanks a lot saved my time.


This comment has been minimized.

jonathanbossenger commented Feb 11, 2017

Brilliant stuff, saved me hours of Googling. Thanks


This comment has been minimized.

roopezero commented Feb 21, 2017

Worked fine for a while, but for some reason this stopped working for me after rebooting. Thunderbird keeps being "Unable to locate mail spool file." even though it exists in /var/mail/user_name. This problem persists even after removing /home/user_name/.thunderbird and reinstalling both postfix and thunderbird.

Any ideas what could cause this?

EDIT: Got it fixed. Turned out my environment variable $MAIL pointed at /home/user_name/Mail instead of /var/mail/user_name. I fixed this by creating a symbolic link to /var/mail/user_name with ln -s /var/mail/user_name /home/user_name/Mail


This comment has been minimized.

chriskerley78910 commented Mar 13, 2017

it works!, thanks man.


This comment has been minimized.

wilensky commented Mar 22, 2017

Seal of apporval


This comment has been minimized.


raelgc commented Apr 27, 2017

@roopezero I usually get this message Unable to locate mail spool file until I send an email to my local account and receive it (this will start the local pool). It's the last step in this tutorial :)


This comment has been minimized.

heartbeathero commented May 4, 2017

Is "ssudo service postfix reload" correct?


This comment has been minimized.

dayze commented Jun 8, 2017

Thanks, save me a lot of time ;)


This comment has been minimized.

burrscurr commented Jun 9, 2017

I had a problem which occured because I already had thunderbird installed and some mail accounts configured there. In the localhost mail configuration part was some non-local smtp server from another mail account selected. This could be fixed with adding a custom smtp server (also in Account settings). Server is localhost, port 25 (can be found out with nmap localhost). Then select this localhost server as smtp server in your local host account.

Even with my struggle this saved a lot of time for me :)


This comment has been minimized.

JonhZono commented Jun 19, 2017

After we set up this local mail server, how about everyone can access that mail server or not,
Can we provide the access right to anyone to access or use that mail or not?


This comment has been minimized.

ChathurikaA commented Jul 13, 2017

I configured local Email Server as you mentioned . But I still get "Unable to locate mail spool file" in Thunderbird . Can you please show me a way to fix it. Also couldn't we create pop3 or Imap store as incoming mail server and smtp server as outgoing mail server in Locally.


This comment has been minimized.

superjoefly commented Aug 5, 2017

@roopezero I had the same issue...thanks for the fix 👍


This comment has been minimized.

minitauros commented Aug 10, 2017

I'm getting an error regarding the SMPT settings. It reads

Sending of the message failed.
The message could not be sent because connecting to Outgoing server (SMTP) localhost failed. The server may be unavailable or is refusing SMTP connections. Please verify that your Outgoing server (SMTP) settings are correct and try again.

Any idea how I can test what is wrong here? When I use for example PHP to send mail, I do receive it, but when I use Thunderbird to send mail, I cannot send it.

SMTP settings in Thunderbird are:

Server Name localhost
Port 587
Connection security none
Authentication method Password, transmitted insecurely
User Name My user name

EDIT Changing the port number to 25 fixed it. While I was typing this all of a sudden I realized :). Just leaving this message here in case anyone else runs into this problem.


This comment has been minimized.

pogster commented Nov 8, 2017

Port 25 was also a really important information for me. Thanks for the guide.


This comment has been minimized.

MegzKay commented Jan 5, 2018

Thank you so much for this really easy to follow guide. I find it rare to find such a simple guide like this for Linux systems. Great job


This comment has been minimized.

lykre commented Jan 26, 2018


thank you for this guide!

I had to run

sudo postmap /etc/postfix/virtual

to create a file called virtual.db or else the server would reject the e-mail I was trying to send. It is also very helpful to check your /var/log/mail.log if things aren't working as expected.


This comment has been minimized.

Azimboy commented Jan 30, 2018

Great article! Many thanks!


This comment has been minimized.

shahnazmshariff commented Feb 10, 2018

Great tutorial! I want to use webmail client (Roundcube/ after logic webmail pro) instead of Thunderbird. Could you, if possible, help me out with this setup, please?


This comment has been minimized.

qoomon commented Feb 19, 2018

just use


This comment has been minimized.

zuhairkareem commented Feb 20, 2018

I made a mistake by giving custom "user" name in /etc/postfix/virtual instead of the correct Linux username and was getting an unknown user error.

to=<customusername@localhost>, orig_to=<customusername@localhost>, relay=local, delay=0.1, delays=0.07/0/0/0.03, dsn=5.1.1, status=bounced (unknown user: "customusername")

As soon as I gave correct one the problem was solved.
Thanks for the fantastic tutorial.


This comment has been minimized.

light2yellow commented Apr 9, 2018

Before starting/restarting postfix I had to do sudo newaliases as per ArchWiki. Otherwise Thunderbird always complains about Unable to locate mail spool file.


This comment has been minimized.

mjrulesamrat commented Aug 3, 2018

Awesome. Worked like charm!
id -u -n
To get Unix user account name to replace


This comment has been minimized.

bochove commented Nov 1, 2018

Is it also possible to catch everything for all domains?
Say I have some application connecting to localhost:25 te send e-mail and I want everything from all domains whatsoever to be delivered to this account.

Under no circumstance may any e-mail actually be deliverable to anything else.

Edit: Found out how to do that:
/etc/postfix/virtual should then contain:

and the /etc/postfix/ should instead have:
virtual_alias_maps = pcre:/etc/postfix/virtual

For this to work you should off course also do:
sudo apt-get install postfix-pcre

Now all e-mail to whatever domain you can think of will be delivered to this mailbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment