Skip to content

Instantly share code, notes, and snippets.

Embed
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 localhost.com 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 localhost.com point to your machine, including this content to the file:

127.0.0.1 localhost.com

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 "@localhost.com".

Example: here, my unique account is rael@localhost.com. But while testing systems, I can use any address like joe@localhost.com, foo@localhost.com, etc, because all will be redirected to rael@localhost.com

  • 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>
@localhost.com <your-user>
  • Save and close the file.
  • Configure postifx to read this file:
    • Open /etc/postfix/main.cf: sudo nano /etc/postfix/main.cf
    • 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.
@raelgc
Copy link
Author

raelgc commented May 1, 2020

@Uysim It appears that your server (or client) are using the secure port instead of port 25. Additionally, check the authentication settings.

@popovserhii
Copy link

popovserhii commented Jun 12, 2020

For testing you can also use next command:
echo "This is the body of the email" | mail -s "This is the subject line" your_email_address

After that, go to Thunderbird and click Get Messages

@ombak
Copy link

ombak commented Jul 23, 2020

I follow this tutorial in Debian 10, but when I try to use thunderbird I always get Unable to locate mail spool file.

This my /etc/host

127.0.0.1 localhost
127.0.0.1 localhost.com

My hostname:

localhost

This my /etc/postfix/main.cf

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost.localdomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = example.com, $myhostname, localhost.localdomain, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = error
relay_transport = error
inet_protocols = all

Thanks

@rpopov
Copy link

rpopov commented Nov 19, 2020

Thank you! Worked perfectly well

@SukeshiniR
Copy link

SukeshiniR commented Feb 4, 2021

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!

@rlogwood
Copy link

rlogwood commented Feb 19, 2021

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 :)

image

@DoctorSubtilis
Copy link

DoctorSubtilis commented Mar 11, 2021

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 main.cf postfix:

readme_directory = no
compatibility_level = 2

smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
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 = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = error
relay_transport = error
inet_protocols = all

@emgrasso
Copy link

emgrasso commented Jul 24, 2021

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.

@Applebois
Copy link

Applebois commented Jul 28, 2021

Thanks,
This is really good post !

@idea-lei
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

-------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 instead

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