Настройка нового сервера postifx#

Нужно установить 2 пакета:

sudo dnf install opendkim postfix

Настройка OpenDKIM#

После установки изменить конфиги:

vim /etc/opendkim.conf
AutoRestart             Yes
AutoRestartRate         10/1h
UMask                   002
Syslog                  yes
SyslogSuccess           Yes
LogWhy                  Yes

Canonicalization        relaxed/simple

ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable

Mode                    sv
SignatureAlgorithm      rsa-sha256

UserID                  opendkim:opendkim

Socket                  inet:12301@127.0.0.1

В /etc/opendkim/KeyTable должны быть включены ключи, например:

mail._domainkey.appworks.ru  appworks.ru:mail:/etc/opendkim/domainkeys/mail.appworks.ru.dkim.private
mailer._domainkey.press.appworks.ru  press.appworks.ru:mailer:/etc/opendkim/domainkeys/mailer.press.appworks.ru.dkim.private

В /etc/opendkim/SigningTable прописываются соответствия ключей и доменов:

*@appworks.ru  mail._domainkey.appworks.ru
*@press.appworks.ru  mailer._domainkey.press.appworks.ru

После синхронизации самих ключей в каталоге /etc/opendkim/domainkeys можно ставить opendkim в автозагрузку.

Чтобы opendkim мог подписывать письма, — нужно выставить корректные права на ключи:

chgrp opendkim /etc/opendkim/*
chmod 600 /etc/opendkim/domainkeys/*
chmod -Rf g+r /etc/opendkim/*
chown -Rf opendkim. /etc/opendkim/domainkeys/

Настройка postfix#

Нужно изменить конфигурацию /etc/postfix/main.cf:

# Main configuration
mydomain = appworks.ru
myhostname = mail.appworks.ru
smtpd_banner = $myhostname ESMTP $mail_name
biff = no

maillog_file = /var/log/postifx/postfix.log
append_dot_mydomain = no
readme_directory = no

myorigin = $myhostname
mydestination = localhost.localdomain, localhost
mynetworks = 10.4.0.0/16

alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases

### Use postmap /etc/postfix/virtual && postfix reload
#virtual_alias_domains = appworkz.ru
#virtual_alias_maps = hash:/etc/postfix/virtual

# SMTP access rules
### Use postmap /etc/postfix/sender_access && postfix reload
smtpd_recipient_restrictions =
    check_sender_access hash:/etc/postfix/sender_access
    reject_unknown_sender_domain
    reject_unauth_destination
    warn_if_reject reject_unverified_sender

smtpd_relay_restrictions = permit_mynetworks

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/postfix-self-signed.crt
smtpd_tls_key_file=/etc/ssl/private.key
smtpd_tls_security_level=may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# DKIM Parameters
milter_protocol=2
milter_default_action=accept
smtpd_milters=inet:127.0.0.1:12301
non_smtpd_milters=inet:127.0.0.1:12301

Затем выпустить самоподписной сертификат:

openssl req -x509 -newkey rsa:2048 -sha256 -days 3650 -nodes \
    -keyout /etc/ssl/private.key \
    -out /etc/ssl/postfix-self-signed.crt \
    -addext 'subjectAltName = DNS:c04-mail.sitefactory.local' \
    -subj "/C=RU/ST=Msk/L=Msk/O=SiteFactory/OU=IT/CN=c04-mail.sitefactory.local"

И добавить в /etc/postfix/sender_access строки:

appworks.ru             OK
press.appworks.ru       OK

Для postfix также нужен файл /etc/postfix/aliases, но в конфигурации он не используется, поэтому достаточно его просто создать:

touch /etc/postfix/aliases

Теперь нужно создать hash. Это можно сделать через postmap:

postmap /etc/postfix/aliases
postmap /etc/postfix/sender_access

Затем нужно запустить службы и поставить их в автозагрузку:

systemctl enable --now postfix opendkim