Postfix, Dovecot, SMTP (07.02.2021)#

Postfix virtual users#

Config vi /etc/postfix/main.cf
virtual_mailbox_maps = hash:/etc/postfix/vmailbox    <= all mailboxes and locations
virtual_alias_maps = hash:/etc/postfix/virtual       <= only for forwarding, mailboxes not needed here, too

If you want to use a local mail client (POP3/IMAP), you need to use Dovecot additionally to handle this. Mailbox locations according to dovecot at vi /etc/dovecot/conf.d/10-mail.conf

mail_location = mbox:~/mail:INBOX=/var/mail/vhosts/inetone/%u
Authentication and ports at vi /etc/dovecot/conf.d/10-master.conf
service pop3-login [ ... }
service auth { unix_listener auth-userdb {...} }
Authentication Driver 10-auth.conf > vi /etc/dovecot/conf.d/auth-system.conf.ext
passdb { ... }
userdb { ... }

After configure dovecot main.cf or master.cf do

service dovecot restart

After configure postfix

vi /etc/postfix/main.cf
vi /etc/postfix/vmailbox	
vi /etc/postfix/virtual
postmap /etc/postfix/vmailbox	<= recreate db file
postmap /etc/postfix/virtual    <= recreate db file
postfix reload                  <= reload config

Postfix and dovecot logging

vi /var/log/mail.log            <= show log
cp /dev/null /var/log/mail.log  <= clean up log
Note there are also mail.info, mail.warn and mail.err file, but mail.log contains all!

New email#

vi /etc/postfix/vmailbox       <= add mail and mailbox location, will be at <virtual_mailbox_base> + location specified
postmap /etc/postfix/vmailbox  <= recreate db file
postfix reload                 <= reload config
Postfix does not need a local user or home folder for an email account, but dovecot needs them, if you use PAM:
useradd <username>             <= create user
passwd <username>              <= set password
mkdir /home/markus.ebel        <= create home folder
chown markus.ebel /home/markus.ebel    <= change home folder owner
chgrp markus.ebel /home/markus.ebel    <= change home folder group

SMTP setup#

vi /etc/postfix/master.cf
and enable
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=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=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
  -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth

SMTP setup error#

warning: SASL: Connect to private/auth failed: No such file or directory
fatal: no SASL authentication mechanisms
Solution: vi /etc/dovecot/conf.d/10-master.conf and enable
  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
  }
Notes:
  • after this file /var/spool/postfix/private/auth gets created automatically
  • you do not need to open a port like 465

Mailserver with postfix and dovecot (29.12.2020)#

based on grund-wissen.de

Install with apt-get install postfix
Start reconfigure wizard with sudo dpkg-reconfigure postfix
Configuration

vi /etc/postfix/main.cf
example at vi /usr/share/postfix/main.cf.dist
list config settings with postconf -d

Check and restart

postfix check
sudo systemctl reload postfix
service postfix reload
service postfix restart <==

vi /etc/aliases

Dovecot #

„Mail Delivery Agent“ (MDA) for POP3 and IMAP.

based on tecadmin.net

apt-get install dovecot-core dovecot-lmtpd dovecot-imapd dovecot-pop3d
apt-get install dovecot-sieve dovecot-solr dovecot-antispam
vi /etc/dovecot/dovecot.conf
/etc/dovecot/conf.d
sudo systemctl enable dovecot.service
sudo systemctl start dovecot.service
sudo systemctl stop dovecot.service
sudo systemctl status dovecot.service

Adding users (03.02.2019)#

You can use any system account

adduser username
Note: to read those local emails in Linux check file /var/mail/<username>
or use command "mail", to be installed with "apt-get install mailutils".

or
Virtual Domain at /etc/postfix/virtual

1. You should have a virtual domain, exclude this at "mydestination", see Postfix guide

vi /etc/postfix/main.cf
    virtual_alias_domains = example.com, example2.com, ...
    virtual_alias_maps = hash:/etc/postfix/virtual
2. create a addresses file (/etc/postfix/virtual)
vi /etc/postfix/virtual
    postmaster@example.com postmaster
    info@example.com       joe
    sales@example.com      jane
    # Uncomment entry below to implement a catch-all address
    # @example.com         jim
    ...virtual aliases for more domains...
    
postmap /etc/postfix/virtual
postmap /etc/postfix/vmailbox
postfix reload
postfix stop
postfix start
newaliases
service postfix restart
postsuper -d ALL  <= delete all mails in queue
vi /var/log/mail.log
grep postfix /var/log/syslog

Virtual alias Domain vs virtual mailbox domain#

Virtual alias domains are not to be confused with the virtual mailbox domains that are implemented with the Postfix virtual(8) mail delivery agent. With virtual mailbox domains, each recipient address can have its own mailbox. With a virtual alias domain, the virtual domain has its own user name space.
vi /etc/postfix/main.cf
    virtual_mailbox_domains = example.com
    virtual_mailbox_base = /var/mail/vhosts   <= base folder fo all mailboxes
    virtual_mailbox_maps = hash:/etc/postfix/vmailbox <= subdirectories per mailbox
    virtual_minimum_uid = 100  <= for safety
    virtual_uid_maps = static:5000 <= system user for all emails
    virtual_gid_maps = static:5000 <= system group for all emails
    virtual_alias_maps = hash:/etc/postfix/virtual <= email addresses

vi /etc/postfix/vmailbox <= assigned folders for each email
    info@example.com    example.com/info
    sales@example.com   example.com/sales/
    # Comment out the entry below to implement a catch-all.
    # @example.com      example.com/catchall

/etc/postfix/virtual:
    postmaster@example.com postmaster

Pop3 / IMAP#

to betested:
  • Postfix is able to deliver POP3, then each mail address need to be mapped to a linux user for a proper password
  • for IMAP you should use dovecot

Forward email with Postfix (Mailserver)#

Postfix is a mail server and it is used to forward mails to username@your-domain.de to any external account.
(Hint: It does not matter, if your-domain.de is a redirection to any other server like euve1234.vserver.de)

The postfix setup is described here,
but I had to modify it a little:
1. Installation

> su
> apt-get update
> apt-get install postfix
> postfix reload
2. Check
> postfix check
> nmap localhost -p 25
> telnet localhost 25
> postconf -d
> tail /var/log/mail.log
  • If nmap does not work, then install it first
> apt-get install nmap
3. Configure Postfix
vi /etc/postfix/main.cf
  • Add/replace at the top
myorigin=your-domain.de
myhostname=your-domain.de
relay_domains=your-domain.de
  • Extend
mydestination = your-domain.de, ...
mynetworks = 5.45.105.135/8 ...

Disable

# myorigin = /etc/mailname
  • Add/replace regarding SPAM rejection
# anti-spam: smtp restrictions
smtpd_recipient_restrictions = reject_invalid_hostname,
        reject_unknown_recipient_domain,
        reject_unauth_destination,
        reject_rbl_client sbl.spamhaus.org,
        permit
 
smtpd_helo_restrictions = reject_invalid_helo_hostname,
        reject_non_fqdn_helo_hostname,
        reject_unknown_helo_hostname
 
smtpd_client_restrictions = reject_rbl_client dnsbl.sorbs.net
  • Open Port 25 for the outside world
inet_interfaces = all
  • Save/Close main.cf and restart postfix (shell)
> service postfix restart

4. Setup email users

  • Edit /etc/aliases
# This means that anyuser@your-domain.de will be forwarded to mailuser@mailprovider.de
anyuser: mailuser@mailprovider.de
Hint: You should setup at least following email addresses
  • webmaster@<your-domain>
  • postmaster@<your-domain>
  • abuse@<your-domain>
  • Enter in shell:
> postconf -e "alias_maps=hash:/etc/aliases"
> newaliases
> postfix reload [or service postfix restart]

Disable email settings from your domain provider#

If your domain provider also offers a mail server for your domain, you should disable that one and create a so called MX-Record, where you put your own server name as mail server. At Strato it must also have an ending dot at the name (?).