User Tools

Site Tools



Install as per normal

 apt-get install postfix
 Choose Internet Site Config.

After Install - Main folder = /etc/postfix
Main file =

Basic Changes:

 Just the name used to identify server
 myhostname =
 # disable lookup of usernames
 disable_vrfy_command = yes
 Remove hash beside delay_warning_time = 4h

Advanced Changes:

===To prevent cross over emails between multiple domains,=== e.g. where and are on the same server. Add the following line into /etc/postfix/ smtpd_sender_restrictions = check_recipient_access hash:/etc/postfix/restrict Create the file: /etc/postfix/restrict OK REJECT To activate/ add this file into postfix, type in the shell → postmap /etc/postfix/restrict Further Details at:,_Part_II

Handle email from Multiple Domains

 vi /etc/postfix/
 #add in the following:
 virtual_maps = regexp:/etc/postfix/virt/kartbuilding_net
 virtual_alias_domains =

 mkdir /etc/postfix/virt/
 vi /etc/postfix/virt/kartbuilding_net
 #add in:
 # mail
 /^$/             localusername

 cd /etc/postfix/virt
 postmap kartbuilding_net
 /etc/init.d/postfix restart

Save and restart postfix. Now the server will handle mail for this domain. No other config required in It will deliver it to the localusername or forward it. If an email is sent and isn't matched a 550 will be sent back. This is miles better that the previous postfix/restrict config above.

Restrict Mail delivery to Local users

On a lists (mailman) server I run - I want to disable mail delivery to local users, however I still want Postfix to deliver mail to /etc/aliases. The line below, which is to be put into /etc/postfix/ forces postfix to only consult $alias_maps (which is: hash:/etc/aliases ).

 local_recipient_maps = $alias_maps

Blocking Spam with spamhaus and Postfix

This is commonly referred to as a “Postfix anti-UCE configuration” (UCE - unsolicited emails). Postfix, with a very simply modification can block incoming email via spamhaus RBLs (Real Time Black-Hole Lists). The following line is to be added to /etc/postfix/

 smtpd_recipient_restrictions reject_rbl_client, reject_rbl_client
 #If there are entries already - thats fine, just comment delimit them.
 #Note: has now changed to as per

The sender is then bounced back an email saying “Blocked by spamhouse” and it is their, or their ISP's responsibility to remove themselves from spamhaus.

Note: “ping” wont resolve. What postfix does when checking an ip (e.g. w.x.y.z), is to “ping”, and if that resolves - that ip is listed as spam. (thanks davisc). <br> Note: Make sure ICMP packets are allowed through the firewall. Otherwise postfix will get a “Destination Not Reachable” and allow the mail through.

See more details at: and and and

Further Info on UCE and Postfix:

 smtpd_sender_restrictions = Restrictions based in the context of the MAIL FROM command. I.e. restrictions based on who emails are from.
 smtpd_recipient_restrictions = Restrictions based on the RCPT TO command. I.e. restrictions based on who emails are been delivered to.
 smtpd_client_restrictions = SMTP server access restrictions in the context of a SMTP connection request.

I have found that blocking mails via DNSBL at “smtpd_sender_restrictions” is not always effective as some spammers can forge the MAIL FROM command. “smtpd_client_restrictions” is the first line of restrictions, and ideally the DNSBL blocks should be put in here, however as outlined on , “smtpd_recipient_restrictions” is the best place to place DNSBL blocks.



Simply send an email to the appropriate address on the above website, and it will reply an automated email with the status of whether your email server is blocking correctly using

Nice :)

Debugging and Testing via Telnet

SENDING AN EMAIL VIA TELNET 25 & Testing forwarding

 mail from:
 rcpt to:

If you get “503 5.5.2 Send hello first”, type “ehlo” as the first line after telneting to host 25.

Test and get working Normal - Should be able to send and revieve via pine etc.

Had to adjust /etc/hosts with domain name (this allowed sending emails ok):       localhost        phidebian


Managing Postfix

Delete an Email from the Queue

For Example - sending an email to someone and it bounces. Default retry is for 3 days. To remove it manually :

 postsuper -d queue_id

Tons more info at:

Delete all Deferred Emails from the Queue

If spam emails are been sent and/or your mail queue fills up, you can delete all deferred emails with the following:

 postsuper -d ALL deferred

Checking Mail logs with pflogsumm

pflogsumm shows all the essential information from mail.log. It groups information into the following headings:

  • Grand Totals - messages sent and recieved.
  • Per-Day Traffic Summary
  • Per-Hour Traffic Daily Average
  • Host/Domain Summary: Message Delivery
  • Host/Domain Summary: Messages Received
  • Senders by message count
  • Recipients by message count
  • Senders by message size
  • Recipients by message size
  • message deferral detail
  • message reject detail
  • message reject warning detail
  • smtp delivery failures
  • Warnings
 apt-get install pflogsumm
 pflogsumm /var/log/mail.log | less

It is a very useful tool and shows an excellent insight into mail delivery and sending on your server.

Show Mail Queue

If mails are deferred etc. and you want to see a list of them:

 postqueue -p

Install Postfix for sending mail via relayhost

On one server, I want it to be only able to send emails only. Therefore the following config will bind it to on port 25. It will also be sending emails using a “smart host”. Below are the uncommented lines only in

 vi /etc/postfix/
 smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
 biff = no
 append_dot_mydomain = no
 myhostname =
 alias_maps = hash:/etc/aliases
 alias_database = hash:/etc/aliases
 myorigin = /etc/mailname
 mydestination =
 relayhost =
 mynetworks =
 mailbox_size_limit = 0
 recipient_delimiter = +
 inet_interfaces =

It must also be checked on that thunder is allowed to relay emails.

Debian Bullseye Config

After a new install of debian bullseye, and after setup or courier and procmail, the following is the config lines added to (Note: there were minor mods added further for sasl see here )

disable_vrfy_command = yes
message_size_limit = 30720000
smtpd_recipient_restrictions = permit_mynetworks,

virtual_maps = regexp:/etc/postfix/virt/kartbuilding_net,
virtual_alias_domains =,
home_mailbox = Maildir/
mailbox_command = /usr/bin/procmail -a "$EXTENSION" DEFAULT=$HOME/Maildir/ MAILDIR=$HOME/Maildir
postfix_smtp.txt · Last modified: 2022/07/21 19:50 by admin