Setting up a local dev mail server August 5, 2018 on Drew DeVault's blog

As part of my work on, it was necessary for me to configure a self-contained mail system on localhost that I could test with. I hope that others will go through a similar process in the future when they set up the code for hacking on locally or when working on other email related software, so here’s a guide on how you can set it up.

There are lots of things you can set up on a mail server, like virtual mail accounts backed by a relational database, IMAP access, spam filtering, and so on. We’re not going to do any of that in this article - we’re just interested in something we can test our email code with. To start, install your distribution of postfix and pop open that /etc/postfix/ file.

Let’s quickly touch on the less interesting config keys to change. If you want the details about how these work, consult the postfix manual.

Also ensure your hostname is set up right in /etc/hosts, something like this: homura.localdomain homura

Okay, those are the easy ones. That just makes it so that your mail server oversees mail delivery for the network (localhost) and delivers mail to local Unix user mailboxes. It will store incoming email in each user’s home directory at ~/Maildir, and will deliver email to other Unix users. Let’s set up an email client for reading these emails with. Here’s my development mutt config:

set edit_headers=yes
set realname="Drew DeVault"
set from="sircmpwn@homura"
set editor=vim
set spoolfile="~/Maildir/"
set folder="~/Maildir/"
set timeout=5
color index blue default ~P

Make any necessary edits. If you use mutt to read your normal mail, I suggest also setting up an alias which runs mutt -C path/to/dev/config. Now, you should be able to send an email to yourself or other Unix accounts with mutt1. Hooray!

To accept email over SMTP, mozy on over to /etc/postfix/ and uncomment the submission service. You’re looking for something like this: inet n       -       n       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_tls_auth_only=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=
#  -o milter_macro_daemon_name=ORIGINATING

This will permit delivery via localhost on the submission port (587) to anyone whose hostname is in $mydestination. A good old postfix reload later and you should be able to send yourself an email with SMTP:

$ telnet 587
Connected to
Escape character is '^]'.
220 homura ESMTP Postfix
250-SIZE 10240000
MAIL FROM:<sircmpwn@homura>
250 2.1.0 Ok
RCPT TO:<sircmpwn@homura> 
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
From: Drew DeVault <sircmpwn@homura>
To: Drew DeVault <sircmpwn@homura>
Subject: Hello world

Hey there 
250 2.0.0 Ok: queued as 8267416366B
221 2.0.0 Bye
Connection closed by foreign host.

Pull up mutt again to read this. Any software which will be sending out mail and speaks SMTP (for example, can be configured now. Last step is to set up LTMP delivery to or any other software you want to process incoming emails. I want most mail to deliver normally - I only want LTMP configured for my test domain. I’ll set up some transport maps for this purpose. In

local_transport = local:$myhostname
transport_maps = lmdb:/etc/postfix/transport

Then I’ll edit /etc/postfix/transport and add these lines:

lists.homura lmtp:unix:/tmp/
homura local:homura

This will deliver mail normally to $user@homura (my hostname), but will forward mail sent to $user@lists.homura to the Unix socket where the LMTP server lives.

Add the subdomain to /etc/hosts: lists.homura.localdomain lists.homura

Run postmap /etc/postfix/transport and postfix reload and you’re good to go. If you have the daemon working, send some emails to ~someone/example-list@lists.$hostname and you should see them get picked up.

  1. Mutt crash course: run mutt, press m to compose a new email, enter the recipient ($USER@$HOSTNAME to send to yourself) and the subject, then compose your email, exit the editor, and press y to send. A few moments later the email should arrive. ↩︎

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~sircmpwn/ [mailing list etiquette]

Articles from blogs I read Generated by openring

Share your feedback about developing with Go

Help shape the future of Go by sharing your thoughts via the Go Developer Survey

via The Go Blog January 18, 2023

Status update, January 2023

Hi all! This month’s status update will be lighter than usual: I’ve been on leave for a while at the end of December. To make up for this, I have some big news: we’ve released Sway 1.8! This brings a whole lot of improvements from wlroots 0.16, as well as som…

via emersion January 16, 2023

SourceHut will (not) blacklist the Go module mirror

Update 2023-01-31: Russ Cox of the Go team reached out to us to address this problem. After some discussion, an acceptable plan was worked out. The Go team is working on deploying an update to the “go” tool to add a -reuse flag, which should substantially re…

via Blogs on Sourcehut January 9, 2023