Search code examples
pythondjangoipv4

Django: Force ipv4 for EMAIL_HOST? (GMail: 421, '4.7.0 Try again later, closing connection.')


If I try to send a mails with Django via settings.EMAIL_HOST, I get this error:

(421, '4.7.0 Try again later, closing connection.')

I found a work-around (GMail 421 4.7.0 Try again later, closing connection)

It works if I use a IPv4 connection (and not IPV6).

EMAIL_HOST = '64.233.184.108'

But this is just a work-around, I would like to have a solution. Because if google changes the IP of the smtp servers, my solution will fail.

How can I tell Django or Python to use IPv4 when I use this?

EMAIL_HOST = 'smtp.gmail.com'

By default my system uses ipv6, and then Google thinks I am a spammer and blocks me with "(421, '4.7.0 Try again later, closing connection.')"


Solution

  • My IPv6 reverse DNS did not resolve. That was the problem.

    After adding my ipv6 address to the DNS things worked.

    Big "Thank you!" to @Melvyn!