Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Mailcow - Speed Up SMTP Sending With IP Whitelist

After having deployed Mailcow, I couldn't help but notice that sending emails was noticeably slower. This made it feel like my website's were "broken" as they became unresponsonsive on any actions that are sending email notifications in the background. Luckily this is easily resolved through adding one's website's IP addresses to the IP whitelist.

Steps

SSH into your mailcow server and go to whichever directory you set it up in. For me this was:

cd $HOME/mailcow-dockerized

Then navigate to the postfix configuration subdirectory:

cd data/conf/postfix

Then edit the custom_postscreen_whitelist.cidr file:

sudo editor custom_postscreen_whitelist.cidr

The file will look like as follows by default:

# Autogenerated by mailcow
# Rules are evaluated in the order as specified.
# Blacklist 192.168.* except 192.168.0.1.
# 192.168.0.1          permit
# 192.168.0.0/16       reject

Simply append a line for each of your server's IP addresses. E.g.

# Autogenerated by mailcow
# Rules are evaluated in the order as specified.
# Blacklist 192.168.* except 192.168.0.1.
# 192.168.0.1          permit
# 192.168.0.0/16       reject

# server1
xxx.yyy.zzz.xyz/32        permit

# www.mywebsite.com
xxx.yyy.zzz.xyz/32        permit

Replace xx.yy.zz.xyz with your server's IP address.

Then save and exit.

The changes should have immediate effect with no need to restart any services.

Still Going Slow? IPv6 Issues

I found that my mail sending was still going slow. I found a thread where someone said they had issues with it going slow and it was to do with the reverse lookups on IPv6. However, the easiest thing is to just disable IPv6. One day, I need to get things going on IPv6, but that day is not today.

References

Last updated: 25th January 2025
First published: 29th November 2024

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch