Skip to content

Instantly share code, notes, and snippets.

@raelgc
Last active September 30, 2024 23:45
Show Gist options
  • Save raelgc/6031274 to your computer and use it in GitHub Desktop.
Save raelgc/6031274 to your computer and use it in GitHub Desktop.
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 [email protected]. But while testing systems, I can use any address like [email protected], [email protected], etc, because all will be redirected to [email protected]

  • 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.
@Applebois
Copy link

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

@AlexDraeger
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'

Source: https://www.it-consulting-stahl.de/2022/06/zugriff-auf-lokale-mails-mit-thunderbird-91/

@raelgc
Copy link
Author

raelgc commented Jan 27, 2023

It appears that Thunderbird has plans to restore movemail someday in the future: https://bugzilla.mozilla.org/show_bug.cgi?id=1802145.

In this meanwhile, people is advising to use BetterBird.

@AlanCW
Copy link

AlanCW commented Feb 15, 2023

Since Unix Mailspool was removed in Thunderbird, a really great option is to install Betterbird 102.8.0-bb30 (14 February 2023). It is a much better implementation of Thunderbird that allows local mail.

https://www.betterbird.eu/

@ABBIDA21
Copy link

but im using just a server without a gui how can i do the step 6****

@nd-dew
Copy link

nd-dew commented Dec 8, 2023

got stuck on step 6, managed to get through it by installing Thunderbird version 45 (cause this tutorial was created around time version 45 was used).

@1egend78
Copy link

1egend78 commented Mar 8, 2024

Hi,
I am surprised that you are accessing emails from Postfix email server via Thunderbird client without installing Dovecot or Courier-IMAP which let the server listen on port 143 (IMAP) and 995 (POP3). The server is listening only port 25 (SMTP) with your configuration. I think it is an incomplete tutorial.

@raelgc
Copy link
Author

raelgc commented Mar 8, 2024

@1egend78 This is a tutorial only for development testing purposes on localhost. It's not intended to be a real email server. In this sense (be a real email server), yes, it's missing other steps.

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