Installation:
sudo apt update
sudo apt install postfix
sudo yum install postfix
Configuration:
/etc/postfix/, with main.cf being the main configuration file.Basic main.cf Settings:
You may want to edit /etc/postfix/main.cf to set:
myhostname = mail.example.com
mydomain = example.com
myorigin = /etc/mailname
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
Postfix Service Control:
sudo systemctl start postfix
sudo systemctl enable postfix
Firewall Configuration:
Make sure to allow SMTP traffic on your firewall. For example, using ufw:
sudo ufw allow 25/tcp
Testing:
You can test your mail server using tools like telnet or by sending an email from the command line:
echo "Test email body" | mail -s "Test Subject" user@example.com
To silently drop outgoing email, you can also use transport map file
transport_maps = hash:/etc/postfix/transport
containing entries like :
email-to-bin@example.com discard:
@domain-to-bin.com discard:
or with regex (regex supports email-to-bin@linux-server-admin.com and email-to-bin+anything@linux-server-admin.com assuming a + delimiter):
/^email-to-bin(\+[^@]+)?@linux-server-admin\.com/ discard:
for regex maybe this is needed (try pcre instead of hash)
transport_maps = pcre:/etc/postfix/transport
then
postmap /etc/postfix/transport
systemctl restart postfix
To reject outgoing email with a message (!), you can use check_recipient_access
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/bad_recipients, permit_mynetworks, reject_unauth_destination, permit
And in /etc/postfix/bad_recipients:
bad_user1@linux-server-admin.com REJECT We don't like him
bad_user2@linux-server-admin.com REJECT Delivery to this user is prohibited
then
systemctl restart postfix
First, you’ll need to accept mail for the nonexistent domain, e.g. by adding it to virtual_mailbox_domains.
Then you’ll need to make a catchall address in virtual_mailbox_maps that delivers it locally, for example:
@example.com throwaway
Last you need to make a local alias for throwaway in /etc/aliases that delivers mail to /dev/null, e.g.:
throwaway /dev/null
then
newaliases
systemctl restart postfix