How I Fixed Gmail Rejecting Emails by Disabling IPv6 in Postfix

October 23, 2024 by
How I Fixed Gmail Rejecting Emails by Disabling IPv6 in Postfix
Hamed Mohammadi
| No comments yet

If you're managing your own mail server, especially with Postfix and ISPConfig, you might occasionally run into problems with sending emails to certain providers. Recently, I encountered an issue where Gmail was rejecting emails from my server with a confusing error:

gmail-smtp-in.l.google.com[2a00:1450:400c:c0b::1a] said: 550-5.7.25 [2a01:4f9:c010:4903::1] The IP address sending this message does not 550-5.7.25 have a PTR record setup...

Despite having a properly configured DNS setup, passing all checks on mail-tester.com with a perfect score of 10/10, and confirming via MXToolBox that my PTR record was correct, Gmail still wasn’t accepting my emails.

The Problem: Postfix and IPv6

The key detail in the error was that Gmail was rejecting my server’s IPv6 address, even though I had configured everything for IPv4. My mail server was set up to use both IPv4 and IPv6 by default, which led Gmail to receive emails from my server's IPv6 address, for which no proper reverse DNS setup was in place.

Even though my IPv4 configuration was perfect, the IPv6 setup wasn’t aligned with Gmail’s strict policies.

The Solution: Disabling IPv6 in Postfix

The fix turned out to be quite simple: I needed to tell Postfix to stop using IPv6 and only use IPv4 for sending emails. Here's how I did it:

Step 1: Edit Postfix Configuration

I accessed the main.cf configuration file for Postfix on my server:

sudo nano /etc/postfix/main.cf

Step 2: Set Postfix to Use IPv4 Only

I found the line that controlled which IP protocols Postfix should use. Initially, it was set to:

inet_protocols = all

This tells Postfix to use both IPv4 and IPv6. To disable IPv6, I changed it to:

inet_protocols = ipv4

Step 3: Save and Restart Postfix

After saving the file, I restarted Postfix to apply the changes:

sudo systemctl restart postfix

Step 4: Test the Changes

I then sent a test email to Gmail and—success! The emails were now being accepted without any issues.

Why This Works

By setting inet_protocols = ipv4, I effectively told Postfix to only use the IPv4 protocol, which was already properly configured with DNS records, including a valid PTR (reverse DNS). Since my mail server no longer attempted to send mail over IPv6 (which Gmail was rejecting), the problem was resolved.

Final Thoughts

If you’re managing your own mail server and run into problems with email rejection, particularly with Gmail, checking how your server is handling IPv6 is an important step. Not all servers need to send email over IPv6, and disabling it might save you a lot of headache if reverse DNS isn’t properly configured.

I hope this post helps anyone who might be dealing with similar issues. Feel free to share your thoughts or ask questions in the comments!

How I Fixed Gmail Rejecting Emails by Disabling IPv6 in Postfix
Hamed Mohammadi October 23, 2024
Share this post
Tags
Archive

Please visit our blog at:

https://zehabsd.com/blog

A platform for Flash Stories:

https://readflashy.com

A platform for Persian Literature Lovers:

https://sarayesokhan.com

Sign in to leave a comment