Setting Up a Mail Server on Local Windows WSL (Postfix and Dovecot)

teetoflame

Victor Okonkwo

Posted on November 22, 2024

Setting Up a Mail Server on Local Windows WSL (Postfix and Dovecot)

We'll set up a simple mail server using Postfix for sending emails and Dovecot for receiving and managing them.

Step 1: Update the System

Update the package index:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Postfix

Install Postfix:

sudo apt install postfix -y
Enter fullscreen mode Exit fullscreen mode

During installation:

  • Select Internet Site when prompted.
  • Enter your domain or server's hostname.

Verify the installation:

sudo systemctl status postfix
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Dovecot

Install Dovecot:

sudo apt install dovecot-core dovecot-imapd -y
Enter fullscreen mode Exit fullscreen mode

Start and enable Dovecot:

sudo systemctl start dovecot
sudo systemctl enable dovecot
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

sudo systemctl status dovecot
Enter fullscreen mode Exit fullscreen mode

Step 4: Configure Postfix

Open the Postfix configuration file:

sudo nano /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

Update or add the following lines:

myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, $mydomain
home_mailbox = Maildir/
Enter fullscreen mode Exit fullscreen mode

Save the file and restart Postfix:

sudo systemctl restart postfix
Enter fullscreen mode Exit fullscreen mode

Step 5: Configure Dovecot

Enable the Maildir format:

sudo nano /etc/dovecot/conf.d/10-mail.conf
Enter fullscreen mode Exit fullscreen mode

Find the line mail_location and update it:

mail_location = maildir:~/Maildir
Enter fullscreen mode Exit fullscreen mode

Save the file and restart Dovecot:

sudo systemctl restart dovecot
Enter fullscreen mode Exit fullscreen mode

Step 6: Test the Mail Server

Create a test user for email:

sudo adduser testuser
Enter fullscreen mode Exit fullscreen mode

Send an email to the test user:

echo "Test email body" | mail -s "Test Subject" testuser
Enter fullscreen mode Exit fullscreen mode

Verify the email:

sudo apt install mailutils -y
mail
Enter fullscreen mode Exit fullscreen mode

Log in as testuser and check the email in the Maildir folder:

su - testuser
cd ~/Maildir
Enter fullscreen mode Exit fullscreen mode

💖 💪 🙅 🚩
teetoflame
Victor Okonkwo

Posted on November 22, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related