2026-07-15

"[Errno 101] Network is unreachable" when trying to send email using Django

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

"[Errno 101] Network is unreachable" when trying to send email using Django

Fixing [Errno 101] Network is unreachable When Sending Emails with Django

Dealing with network errors when trying to perform essential tasks like sending emails can be incredibly frustrating. If you are running a Django application on a remote server—like your Bluehost instance—and encounter an error such as [Errno 101] Network is unreachable, it signals a problem at the operating system or network level, rather than an issue with your Python or Django code itself.

As a senior developer, I can tell you that this specific error usually points toward connectivity issues between your application server and the external SMTP server (in this case, smtp.gmail.com). Since it works locally but fails on the remote server, the problem almost certainly lies in the server's environment configuration rather than the Django settings themselves.

Here is a comprehensive guide to diagnosing and fixing this network connectivity issue.

Understanding the Root Cause: Why Network Unreachable?

The error code [Errno 101] Network is unreachable means that the operating system could not establish a route to the destination host. In the context of sending mail via SMTP, this usually points to one of three core issues on your server:

  1. Firewall Blocking: The most common culprit. The server's firewall (like iptables or security groups provided by Bluehost) is actively blocking outbound connections on the necessary port (e.g., port 587 for TLS).
  2. Outbound Connectivity Issues: The server itself might have restricted outbound traffic, preventing connections to external SMTP providers.
  3. DNS Resolution Failure: Less common, but if the server cannot correctly resolve smtp.gmail.com into an IP address, the connection attempt will fail immediately.

Step-by-Step Troubleshooting Guide

Since your configuration details look standard:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'FakePassword' # Note: This should be an App Password, not your main account password!
EMAIL_PORT = 587

We need to focus our investigation on the server environment.

1. Check Server Firewall Configuration (The Priority)

Log into your Bluehost control panel or use SSH to inspect the server's firewall rules. Ensure that outbound traffic on port 587 (or whatever port you are using) is explicitly allowed. If you are running a VPS or dedicated server, check the local OS firewall settings immediately.

2. Verify Outbound Network Access

Try testing connectivity directly from your remote server via the command line. Use tools like telnet or nc (netcat) to see if the connection is physically possible:

# Example test on your remote server
telnet smtp.gmail.com 587

If this command hangs or immediately returns a refusal, it confirms that an intermediate layer—either a host-level firewall or a network security group—is blocking the traffic before it even reaches the SMTP service.

3. Address Authentication and Security (The Gmail Specific Fix)

While Errno 101 is a network error, remember that using standard Gmail accounts requires specific authentication steps:

  • App Passwords: If you are using a standard Gmail account, Google often blocks direct login attempts from external applications for security. You must generate an App Password specifically for this application, rather than using your regular account password in EMAIL_HOST_PASSWORD.
  • TLS/SSL Handshake: Since you have EMAIL_USE_TLS = True and port 587, ensure that the TLS handshake is not being prematurely terminated by a network inspection device.

Best Practices for Robust Backend Communication

When building robust applications, especially when dealing with external services, it’s vital to design systems that account for potential failures. This principle of handling external dependencies gracefully is central to modern backend development, whether you are using Laravel or Django. For instance, in frameworks like Laravel, managing external API calls requires careful error handling and retry logic.

To make your application resilient against these types of network drops, always implement retries with exponential backoff for critical operations like sending emails. Do not rely on a single attempt. If the initial connection fails due to Errno 101, the system should pause briefly and try again.

Conclusion

The [Errno 101] Network is unreachable error when using Django email settings almost always indicates a problem with outbound network connectivity or firewall rules on your hosting server, rather than an issue within the Python code. By systematically checking your server's firewall, testing direct connectivity via tools like telnet, and ensuring proper application-specific authentication (like Google App Passwords), you will successfully resolve this connectivity roadblock and get your emails delivered reliably.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.