Skip to content

Instantly share code, notes, and snippets.

@oko
Last active December 17, 2015 11:59
Show Gist options
  • Save oko/5606930 to your computer and use it in GitHub Desktop.
Save oko/5606930 to your computer and use it in GitHub Desktop.
Notes on mail server configuration.

WORK IN PROGRESS

Mail Server Configuration with Virtual Domains

Security Basics

  • Use SSL. You're passing credentials and private communications over the wire, so you'd better encrypt it.
  • Don't be an open relay. Forwarding spammers' mail is a good way to get your IP blacklisted and receive some nastygrams from other webmasters
  • chroot if possible.

Software

I use Postfix and Dovecot. They're reasonably well-behaved.

sudo apt-get install postfix dovecot-imapd

That will get you the base packages necessary to get started.

Basic Postfix

Postfix is a popular and sensibly-written mail transfer agent (MTA). It's full-featured and fast.

Main Configuration: /etc/postfix/main.cf

main.cf is Postfix's primary configuration file.

Basic Variables

  • myhostname: this mail server's hostname
  • myorigin: domain to use for locally-posted mail sending and delivery
  • mydestination: domains whose mail is handled by this server
  • mynetworks: trusted networks (i.e., the IP block(s) your other non-mail servers are in)
  • relayhost: domain to relay mail to when the destination is not a domain in mydestination
  • inet_interfaces: the interfaces Postfix should listen on. Normally, all
  • home_mailbox: the pathname to deliver mail to relative to a user's home directory
  • alias_maps/alias_database: aliases used for local mail delivery

Virtual Domain Variables

  • ``

A Basic main.cf

# Use /etc/mailname to determine origin
myorigin = /etc/mailname
myhostname = mail.domain.net
# Accept mail for localhost and domain.net
mydestination = domain.net, mail.domain.net, localhost, localhost.localdomain
# Allow loopback deliveries and deliveries from a hypothetical server block
# at 192.168.1.0/24
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.0/24
# Don't relay mail not destined for here
relayhost = 
# Listen on all interfaces
inet_interfaces = all

# Use qmail Maildir format
# -- qmail format used if name has a trailing /
home_mailbox = Maildir/

# Configure alias files
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

# Allow user+tag@domain.net style addressing
recipient_delimiter = +

# Set a connection banner
smtpd_banner = $myhostname ESMTP $mail_name

# Disable local mail notifications
biff = no

# Unlimited mailbox size
mailbox_size_limit = 0

Basic Dovecot

Dovecot is one of the popular IMAP client access servers. Like Postfix, it has a rich feature set and solid performance.

Virtual Mail

If you're just doing email for a single domain, and you (or people you trust with local accounts) are the only user, you can just create the requisite system accounts and aliases and call it a day. Otherwise, you'll need to roll some of the virtual mail features of Postfix and Dovecot.

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