You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 16.04 LTS本地搭建简易邮件服务器?

Hey Alfred, I’ve got you covered with a dead-simple local test mail server setup for Ubuntu 16.04 LTS that checks all your boxes. We’ll use Postfix (for sending mail) and Dovecot (for retrieving mail) – they’re lightweight, easy to tweak, and work entirely offline. Let’s dive in:

Step 1: Install the Required Tools

First, update your package list and install the core packages:

sudo apt update && sudo apt install postfix dovecot-core dovecot-imapd

When the Postfix setup wizard pops up:

  • Select Local only (this ensures the server only listens to your local machine, no internet needed)
  • Set the system mail name to localhost (this will be our domain for the email addresses)
Step 2: Create Local User Accounts

Your sender@localhost and receiver@localhost addresses map directly to local Linux users. Let’s create them and set passwords (you’ll need these for Thunderbird later):

# Create sender user and set password
sudo useradd -m -s /bin/bash sender
sudo passwd sender

# Create receiver user and set password
sudo useradd -m -s /bin/bash receiver
sudo passwd receiver

The -m flag creates a home directory for each user (where their mail will be stored), and -s sets a default shell.

Step 3: Configure Postfix for Local Delivery

Edit Postfix’s main configuration file to lock it down for local use:

sudo nano /etc/postfix/main.cf

Make sure these settings are present (adjust if they’re missing or incorrect):

myhostname = localhost
mydomain = localhost
myorigin = $mydomain
inet_interfaces = loopback-only  # Only listen to local connections
mydestination = $myhostname, localhost.$mydomain, localhost
home_mailbox = Maildir/  # Use Maildir format (Dovecot-friendly)

Save the file (Ctrl+O, Enter, then Ctrl+X) and restart Postfix to apply changes:

sudo systemctl restart postfix
Step 4: Configure Dovecot to Serve Mail

Dovecot handles retrieving mail via IMAP (which Thunderbird uses). Let’s tweak its settings:

1. Enable IMAP

Edit the main Dovecot config:

sudo nano /etc/dovecot/dovecot.conf

Find the protocols line and set it to:

protocols = imap

2. Set Mail Storage Location

Edit the mail storage config:

sudo nano /etc/dovecot/conf.d/10-mail.conf

Set the mail_location to:

mail_location = maildir:~/Maildir

3. Allow Plaintext Authentication (Local Only)

Since we’re only using this server locally, plaintext auth is safe. Edit the auth config:

sudo nano /etc/dovecot/conf.d/10-auth.conf

Update these lines:

disable_plaintext_auth = no
auth_mechanisms = plain login

4. Restart Dovecot

Apply all changes by restarting Dovecot:

sudo systemctl restart dovecot
Step 5: Test Local Mail Delivery

Let’s verify sending mail works before setting up Thunderbird:

  1. Switch to the sender user:
    su - sender
    
  2. Send a test email to the receiver:
    echo "This is a test email body!" | mail -s "Local Test Email" receiver@localhost
    
  3. Switch to the receiver user and check for the mail:
    su - receiver
    ls ~/Maildir/new/  # You should see a new file here
    cat ~/Maildir/new/*  # View the email content
    

If you see the email content, the server is working locally!

Step 6: Configure Thunderbird

Now let’s set up Thunderbird to use your local server:

For sender@localhost:

  1. Open Thunderbird → Click Email under "Create a new account"
  2. Enter:
    • Your name: (e.g., "Test Sender")
    • Email address: sender@localhost
    • Password: (the password you set for the sender user)
  3. Click Continue – Thunderbird might fail auto-config, so select Manual config
  4. Set these values:
    • Incoming (IMAP)
      • Server hostname: localhost
      • Port: 143
      • Connection security: None
      • Authentication method: Normal Password
      • Username: sender
    • Outgoing (SMTP)
      • Server hostname: localhost
      • Port: 25
      • Connection security: None
      • Authentication method: Normal Password
      • Username: sender
  5. Click Done to finish setup

Repeat the exact same steps for receiver@localhost (use the receiver’s password and username).

Troubleshooting Tips
  • If mail isn’t sending/receiving, check the logs:
    • Postfix logs: sudo tail -f /var/log/mail.log
    • Dovecot logs: sudo tail -f /var/log/dovecot.log
  • Ensure your firewall allows local connections to ports 143 (IMAP) and 25 (SMTP) – Ubuntu 16.04’s default firewall usually allows this, but you can verify with sudo ufw status

内容的提问来源于stack exchange,提问作者Alfred

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:00:17