Skip to content

Instantly share code, notes, and snippets.

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

Setup a Local Only SMTP 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.
Copy link

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.

Thank you. This worked for me!

Copy link

Really appreciate this, thank you! I'm running Ubuntu 20.04 LTS and Thunderbird Mail 1:68.10.0+build1-0ubuntu0.20.04.1.

To add to previous comments from other current users of Thunderbird mail, like myself, I've enclosed a screen shot of my outgoing SMTP Server for the postfix server account created as per the instructions. Replace the blue splat with your account name :)


Copy link

Thank you, but I have a problem, both in receiving and in sending e-mail.
Sending an e-mail (with another account) to duns@localhost I get this error message:

DNS Error: 765891 DNS type 'mx' lookup of localhost responded with code NXDOMAIN Domain name not found: localhost  

Sending an email with localhost I get this message
An error occurred while sending mail. The mail server responded: 5.1.1 <mymail@mydomain>: Recipient address rejected: mydomain. Please check the message recipient "<mymail@mydomain>" and try again.

my postfix:

readme_directory = no
compatibility_level = 2


smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = duns-neon.home
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_maps = hash:/etc/postfix/virtual
mydestination = $myhostname, duns-neon, localhost.localdomain, localhost
relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = error
relay_transport = error
inet_protocols = all

Copy link

The instructions are clear for Postfix, but current Thunderbird versions are fussy.
I'm on Ubuntu 20.04, with Thunderbird 78.11.0. netstat indicates that postfix is listening on port25.
But Thunderbird says it can't connect to the account for incoming messages
Thunderbid seemd to want to prepend a . to the server names: I assumed since that needs to be removed for the SMTP settings, the same should hold for the IMAP. Is there a combination of port and security settings that works?
143, connection security: none, password transmitted insecurely does not seem to work. Thunderbird is also not prompting for a password, but it doesn't react well to being told to remember an initial password either.

Copy link

This is really good post !

Copy link

idea-lei commented Mar 15, 2022

thanks for the tutorial.
but I could not find the correct option in section 6 -> Select "Unix Mailspool (Movemail)"
it was only one option "Newsgroup account"
how could I fix this? thx in advance

for users who does not find the "unix mailspool" option sam as me:
thunderbird has removed the "unix mailspool" support since version 91. if want to follow this instruction, install a older verison instead

Copy link

AlexDraeger commented Oct 17, 2022

First, thanks for this tutorial:)

thanks for the tutorial. but I could not find the correct option in section 6 -> Select "Unix Mailspool (Movemail)" it was only one option "Newsgroup account" how could I fix this? thx in advance

-------Edit------- for users who does not find the "unix mailspool" option sam as me: thunderbird has removed the "unix mailspool" support since version 91. if want to follow this instruction, install a older verison instea

another option is to simply show the mail textfile in thunderbirds local folders.
Notice that this is no elegant version but it seems that unix movemail will not be supported in the future

  1. Thunderbird: Right click on 'Local Folders' -> Settings. Copy your the 'Local Directory'-Path.
  2. Close Thunderbird
  3. Create a new Symlink via Terminal:
    NOTE: Eather escape the whitespace or keep your path (Local Directory) between quotation marks
ln -s /var/mail/<username> '<LOCAL DIRECTORY>'
  1. Change Permissions for /var/mail/<username> to 666 or 600
  2. You will find incoming mails in your Local Folders/'username'


Copy link

raelgc commented Jan 27, 2023

It appears that Thunderbird has plans to restore movemail someday in the future:

In this meanwhile, people is advising to use BetterBird.

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