Mail (Postfix and Dovecot)
A starting point for a single-domain mail server, SMTP with Postfix and IMAP with Dovecot.
jailops app install mailAdd --dry-run to see every step first. From the console: open Apps, pick Mail (Postfix and Dovecot) and press Install; the dialog takes the jail name, the network and the storage, and Preview steps shows the plan before anything runs. See the console.
About
Postfix receives mail for one domain on port 25 and takes mail from your users on the submission port 587; Dovecot serves the mailboxes over IMAP. Mail users are system users of the jail with their homes under /home/mail, and mail is delivered to Maildir/ in each home.
This is a starting point: the domain is example.com until you change it, there is no TLS until you add a certificate (so clients cannot log in from other machines yet), and there is no spam filter, no DKIM signing and no webmail. The notes list the next steps and the DNS records.
What you get
Ports
25/tcpsmtp exposeMail from other servers to your domain.587/tcpsubmission exposeMail from your users; needs TLS and a login, so not usable until a certificate is set.143/tcpimap exposeIMAP; logins are refused without TLS except from the jail itself.993/tcpimapsIMAP over TLS; not listening until a certificate is configured.
Data on its own datasets
/home/mailvolumehome-mailThe mail users' homes and their Maildir mailboxes./var/spool/postfixvolumevar-spool-postfixThe Postfix queue.
Configuration
/usr/local/etc/postfix/main.cfPostfix settings (domain, TLS); 'postfix reload' applies a change. Restart:service postfix restart./usr/local/etc/postfix/master.cfThe Postfix services, including submission on 587. Restart:service postfix restart./usr/local/etc/dovecot/dovecot.confDovecot settings (written at the installation for Dovecot 2.3). Restart:service dovecot restart.
Logs
/var/log/maillogBoth servers log to syslog, facility mail.
Health check
TCP: port 25 accepts a connection, retried for up to 60 seconds.
Services
postfix: enabled and started;sendmail_enable="NONE"dovecot: enabled and started
Setup, once, before the first start
Eleven commands, run in the jail as argv, without a shell:
/bin/sh -c "cd /usr/local/etc/postfix && for f in main.cf master.cf; do [ -e $f ] || cp $f.sample $f; done"/usr/local/sbin/postconf -e "mydomain = example.com" "myhostname = ma…/usr/local/sbin/postconf -e "mydomain = example.com" "myhostname = mail.example.com" "myorigin = $mydomain" "mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain" "inet_interfaces = all" "home_mailbox = Maildir/" "alias_maps = $default_database_type:/etc/mail/aliases" "alias_database = $default_database_type:/etc/mail/aliases" "smtpd_sasl_type = dovecot" "smtpd_sasl_path = private/auth"/usr/local/sbin/postconf -M "submission/inet=submission inet n - n - - smtpd"/usr/local/sbin/postconf -P submission/inet/syslog_name=postfix/submi…/usr/local/sbin/postconf -P submission/inet/syslog_name=postfix/submission submission/inet/smtpd_tls_security_level=encrypt submission/inet/smtpd_sasl_auth_enable=yes submission/inet/smtpd_client_restrictions=permit_sasl_authenticated,reject/usr/local/sbin/postfix set-permissions/usr/local/sbin/postfix check/usr/local/sbin/postalias /etc/mail/aliases/bin/mkdir -p /usr/local/etc/mail/bin/sh -c "printf '%s\\t%s\\n' sendmail /usr/local/sbin/sendmail sen…/bin/sh -c "printf '%s\\t%s\\n' sendmail /usr/local/sbin/sendmail send-mail /usr/local/sbin/sendmail mailq /usr/local/sbin/sendmail newaliases /usr/local/sbin/sendmail > /usr/local/etc/mail/mailer.conf"/bin/sh -c "f=/usr/local/etc/dovecot/dovecot.conf; [ -e $f ] || print…/bin/sh -c "f=/usr/local/etc/dovecot/dovecot.conf; [ -e $f ] || printf '%s\\n' '# Starter configuration of the mail app (Dovecot 2.3); see its notes.' 'protocols = imap' 'ssl = no' 'disable_plaintext_auth = no' 'mail_location = maildir:~/Maildir' 'passdb {' ' driver = pam' '}' 'userdb {' ' driver = passwd' '}' 'service auth {' ' unix_listener /var/spool/postfix/private/auth {' ' mode = 0660' ' user = postfix' ' group = postfix' ' }' '}' 'service imap-login {' ' inet_listener imaps {' ' port = 0' ' }' '}' > $f"/usr/local/bin/doveconf -n
After the installation
The notes of the definition, shown after the installation too.
A starting point: example.com, no TLS. In the jail (jailops shell NAME):
- Domain: postconf -e
mydomain = YOUR.DOMAINmyhostname = mail.YOUR.DOMAIN, then postfix reload. - A user: pw useradd -n alice -d /home/mail/alice -m -s /usr/sbin/nologin, then passwd alice. Mail to alice@YOUR.DOMAIN lands in ~alice/Maildir.
- TLS: put a certificate and key in the jail, then postconf -e
smtpd_tls_cert_file = CERTsmtpd_tls_key_file = KEYsmtpd_tls_security_level = mayand postfix reload; in dovecot.conf set ssl = required, ssl_cert = <CERT, ssl_key = <KEY, delete the port = 0 line of the imaps listener and service dovecot restart. Then clients use 587 and 993 with a login.
DNS for YOUR.DOMAIN (the jail's public address must be reachable on 25):
- A/AAAA: mail.YOUR.DOMAIN -> the address; PTR of the address back to mail.YOUR.DOMAIN (set by whoever owns the address).
- MX: YOUR.DOMAIN -> 10 mail.YOUR.DOMAIN
- SPF: TXT on YOUR.DOMAIN "v=spf1 mx -all"
- DKIM: needs a signing service, which this app does not include; without it, large providers may file your mail as spam.
- DMARC: TXT on _dmarc.YOUR.DOMAIN "v=DMARC1; p=none; rua=mailto:postmaster@YOUR.DOMAIN"
Many networks block outgoing port 25; check before relying on it.
How it connects
jailops app allow mail from @web
This opens the ports 25/tcp, 587/tcp, 143/tcp, 993/tcp of this app to the jail web, and nothing else. The service itself must listen on the jail's address and accept the client.
An installed app is closed: nothing reaches it, not even its own network, until you allow a source. A source is a jail (@web), a jail of another project (@project/web), an address set, an address or prefix, or host. jailops app access mail lists who may connect. The names here are jail names: jailops app install names the jail after the app unless --name says otherwise.