Software⏱️ 4 min read📅 2026-06-15

How to Fix: Why am I getting a “Connection is closed by foreign host” error?

Connection is closed by foreign host error occurs when the remote server closes the connection unexpectedly. Check if the mail server is down or experiencing issues.

Quick Answer: Check if the mail server is up and running, and try again after a few minutes.

The 'Connection is closed by foreign host' error occurs when your email client or application fails to establish a secure connection with the mail server, often due to incorrect port numbers or invalid host names. This issue affects users who are trying to send emails through their email clients or applications.

This error can be frustrating as it prevents you from sending emails, and it may also lead to delays in receiving important messages. In this guide, we will walk you through the root causes of this error and provide steps to resolve it using two primary fix methods.

🛑 Root Causes of the Error

  • The primary reason for the 'Connection is closed by foreign host' error is that the mail server is not accepting connections from your email client or application due to incorrect port numbers. The standard SMTP port number is 587, but some mail servers may use alternative ports like 25 or 465. If you are using an incorrect port number, the connection will be closed by the foreign host.
  • Another possible reason for this error is that the host name of your mail server is invalid or not recognized by your email client or application. This can happen if the mail server's DNS record is not correctly configured or if there is a typo in the host name.

✅ Best Solutions to Fix It

Resolving the issue by using the correct port number

  1. Step 1: Step 1: Check your email client or application settings to ensure that you are using the correct SMTP port number. For most modern email clients, the default port number is 587. If you are unsure about the port number, check your mail server's documentation or contact their support team for assistance.
  2. Step 2: Step 2: If you are still experiencing issues after checking your settings, try using a different port number. Some popular alternative port numbers include 25 and 465. However, keep in mind that these ports may not be secure, so use them at your own risk.
  3. Step 3: Step 3: Once you have confirmed the correct port number, restart your email client or application to ensure that it is using the new settings.

Resolving the issue by verifying the host name

  1. Step 1: Step 1: Check your mail server's DNS records to ensure that they are correctly configured. You can use online tools like Whois or DNS lookup to verify the host name and IP address of your mail server.
  2. Step 2: Step 2: If you find any issues with your DNS records, contact your mail server's administrator or support team to resolve them. They may need to update the DNS records or configure additional settings to ensure that your email client or application can connect successfully.

💡 Conclusion

To summarize, the 'Connection is closed by foreign host' error occurs due to incorrect port numbers or invalid host names. By following the steps outlined in this guide, you should be able to resolve the issue and send emails successfully. Remember to always check your email client or application settings and verify the host name of your mail server before attempting to send emails.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions