§2024-04-30

sudo apt remove --purge postfix dovecot-imapd dovecot-pop3d

Note: This guide does not cover setting up Postfix Virtual Domains. For information on Virtual Domains and other advanced configurations see References.


¶Install Postfix

sudo apt install postfix

It is OK to accept defaults initially by pressing return for each question. Some of the configuration options will be investigated in greater detail in the configuration stage.

¶Configure Postfix

There are four things you should decide before configuring:

  1. The for which you’ll accept email (we’ll use mail.example.com in our example)
  2. The network and class range of your mail server (we’ll use 192.168.0.0/24)
  3. The username (we’re using steve)
  4. Type of mailbox format (mbox is the default, but we’ll use the alternative, Maildir)

To configure postfix, run the following command:

sudo dpkg-reconfigure postfix

But, make a copy first sudo cp -v /etc/postfix/main.cf /etc/postfix/main.cf.ori

To configure postfix, run the following command:

sudo dpkg-reconfigure postfix

pkg-reconfigure-postfix-08.png

¶Configure mailbox format

sudo postconf -e 'home_mailbox = Maildir/'

alexlai@h2Jammy:~$ grep mailbox /etc/postfix/main.cf
mailbox_size_limit = 0
alexlai@h2Jammy:~$ sudo postconf -e 'home_mailbox = Maildir/'
alexlai@h2Jammy:~$ grep mailbox /etc/postfix/main.cf
mailbox_size_limit = 0
home_mailbox = Maildir/

This will place new mail in /home/<username>/Maildir so you will need to configure your Mail Delivery Agent (MDA) to use the same path.

$ sudo systemctl restart postfix
alexlai@h2Jammy:~$ ls ls ~/Maildir
ls: cannot access 'ls': No such file or directory
ls: cannot access '/home/alexlai/Maildir': No such file or directory

>if not exists `mkdir ~/Maildir`

alexlai@h2Jammy:~$ mail -s "test Maildir" alexlai@h2jammy.yushei.net
Cc: 
Subject: see whenn Maildir will be created
Hi
Bye
,
 
alexlai@h2Jammy:~$ ls -l  ~/Maildir/
total 0
drwx------ 2 alexlai alexlai  627 09:33 cur
drwx------ 2 alexlai alexlai 5327 09:33 new
drwx------ 2 alexlai alexlai  627 09:33 tmp

alexlai@h2Jammy:~$ ls -l  ~/Maildir/new/
total 4
-rw------- 1 alexlai alexlai 107227 09:33 1714181601.V803I6000092cM695063.h2Jammy

alexlai@h2Jammy:~$ ls -l  ~/Maildir/tmp/
total 0

alexlai@h2Jammy:~$ ls -l  ~/Maildir/cur
total 0
# using ~/Maildir for mail
export MAIL=~/Maildir

Up to now, /etc/postfix/main.cf is like this

alexlai@h2Jammy:~$ sudo cp -v /etc/postfix/main.cf /etc/postfix/main.cf.ori 
[sudo] password for alexlai: 
'/etc/postfix/main.cf' -> '/etc/postfix/main.cf.ori'
alexlai@h2Jammy:~$ cat   /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 3.6 on
# fresh installs.
compatibility_level = 3.6



# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = h2Jammy.yushei.net
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = h2Jammy.yushei.net
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/16
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/