Postfix mail server config

Here is an example of a basic Postfix mail server configuration:

main.cf

This is the main configuration file for Postfix. It sets various parameters that control the behavior of the mail server.

# Main configuration file for Postfix

# Daemon options
inet_interfaces = loopback-only
mydestination = example.com
myhostname = mail.example.com
myorigin = $myhostname

# Mailbox settings
home_mailbox = Maildir/

# Relay settings
mynetworks = 127.0.0.0/8 [::1]/128
relayhost =

# Authentication settings
smtpd_sasl_type = dovecot
smtpd_sasl_path = /usr/lib/dovecot/sasl2/smtpd
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

# Spam and virus scanning
content_filter = amavis:[127.0.0.1]:10024
milter_default_action = accept

# Logging
smtpd_tls_loglevel = 1
smtpd_tls_cert_file = /etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/example.com/privkey.pem

master.cf

This file defines the services that Postfix provides and the commands that are executed to handle incoming and outgoing mail.

# Master configuration file for Postfix

# Service definitions
smtp      inet  n       -       -       -       -       smtpd
submission inet n       -       -       -       -       smtpd
smtps     inet  n       -       -       -       -       smtpd

# Service options
smtp      -o syslog_name=postfix/smtp
submission -o syslog_name=postfix/submission
smtps     -o syslog_name=postfix/smtps

# Relay settings
relay     -o relayhost=smtp.example.com

postconf

This command is used to set and display Postfix configuration parameters.

Example:

postconf -e "mydestination = example.com"
postconf -e "myhostname = mail.example.com"
postconf -e "mynetworks = 127.0.0.0/8 [::1]/128"

Dovecot configuration

Dovecot is used for IMAP and POP3 services. Here is an example of a basic Dovecot configuration:

10-auth.conf

# Authentication settings
auth_mechanisms = plain login

10-config.conf

# Configuration settings
mail_location = maildir:~/Maildir
first_valid_dsn = 550

20-imap.conf

# IMAP settings
imap_capabilities = IMAP4rev1

20-pop3.conf

# POP3 settings
pop3_capabilities = POP3

postfix-dovecot-sasl.conf

This file is used to configure the SASL authentication mechanism.

# SASL authentication settings
auth_username_format = %n

Let's Encrypt configuration

To use Let's Encrypt certificates with Postfix, you need to configure the smtpd_tls_cert_file and smtpd_tls_key_file parameters in the main.cf file.

You also need to install the letsencrypt package and run the following command to obtain the certificates:

letsencrypt certonly --webroot --webroot-path=/var/www/html --email [email protected] --agree-tos --non-interactive --expand --domains -d example.com

Replace example.com with your domain name.

Note: This is just a basic example configuration and you may need to adjust it to fit your specific needs. Additionally, you should ensure that your system is properly configured and that you have installed all necessary packages before running Postfix and Dovecot.