“Connection to server failed” (Gmail Android)

When opening the Gmail app on an Android device—or when adding an Exchange, Microsoft 365, or third-party IMAP account to the Android Gmail client—the synchronization banner may stall with the error “Connection to server failed,” “Can’t connect to server,” or “Couldn’t open connection to server.”

Quick Answer

On Android, this error occurs when background synchronization is disabled, battery optimization kills the Gmail exchange services, or outgoing server ports (e.g., IMAP 993, SMTP 587) are blocked by a private DNS provider or VPN. To resolve it, clear the Gmail app cache, toggle Android auto-sync off and on, and exclude Gmail from battery optimization.


What the Signal Means

Unlike a simple “Incorrect Password” prompt, “Connection to server failed” indicates an operating system or transport-layer network failure. The Gmail app (or its underlying Android service component, com.google.android.gm.exchange) initiated an open socket request to the mail host, but:

  • The TCP handshake timed out before receiving a response;
  • The local operating system actively severed the connection due to battery-saving policies; or
  • A local security profile, proxy, or VPN dropped the packets during transport.

Diagnostic Branching

"Connection to server failed" (Android)
│
├── Does the error occur across both Wi-Fi and Cellular data?
│   ├── Wi-Fi only ──► Router firewall, MTU sizing, or internal network DNS failure.
│   └── Both       ──► Device-level configuration, battery saving, or OS socket block.
│
├── Is the account a third-party account (Outlook/Exchange/IMAP) inside Gmail?
│   ├── YES ──► Port, certificate trust, or modern auth token failure.
│   └── NO  ──► Android System Google Play Services sync error.

Progressive Diagnostic Steps

Step 1: Force a Global Sync Reset

Android’s global background synchronization service can enter an unresponsive state after network switches (such as transitioning from mobile data to a weak Wi-Fi connection):

  1. Open your device’s Settings.
  2. Scroll down and tap Passwords & accounts (or Users & accounts depending on manufacturer).
  3. Find the toggle for Automatically sync app data.
  4. Turn it Off, wait 10 seconds, and turn it back On.
  5. Tap on the specific account reporting the failure, tap Account sync, and verify that the toggle for Gmail is active.
  6. Tap the three-dot menu in the top-right corner and select Sync now.

Step 2: Clear Application Cache and Data

A corrupted local mailbox index can prevent the Android sync thread from completing its handshake:

  1. Go to Settings > Apps > See all apps > Gmail.
  2. Tap Force Stop, then tap OK.
  3. Tap Storage & cache.
  4. Tap Clear cache.
  5. Open the Gmail app to test synchronization.
  6. If the connection continues to fail, return to the storage menu and tap Clear storage (or Clear data).(Note: This does not delete any cloud data; it only purges local temporary indexes and forces a clean sync from the server).

Step 3: Disable Battery Optimization Restrictions

Aggressive manufacturer battery profiles (common on Samsung, Xiaomi, and OnePlus devices) often terminate background socket connections to conserve power:

  1. Navigate to Settings > Apps > Gmail.
  2. Tap App battery usage (or Battery).
  3. Switch the profile from Optimized to Unrestricted.
  4. Return to the main app settings page and confirm that Mobile data & Wi-Fi > Background data and Unrestricted data usage are both enabled.

Step 4: Check for Private DNS and VPN Interference

Modern Android versions incorporate native Private DNS (DNS-over-TLS). If the configured DNS provider is experiencing outages or blocks mail infrastructure, Gmail will fail to resolve incoming and outgoing server hostnames:

  1. Go to Settings > Network & internet > Private DNS.
  2. Temporarily set it to Off (or Automatic instead of a custom hostname).
  3. Disconnect any active VPN clients or ad-blocking profiles (such as AdGuard or WireGuard).
  4. Launch Gmail and pull down on the inbox to refresh.

Step 5: Manually Re-verify Server Port Parameters (Non-Gmail Profiles)

If you are syncing an external account (such as Yahoo, Outlook, or a custom corporate domain) through the Android Gmail app:

  1. Open Gmail and tap your profile icon in the upper right.
  2. Select Manage accounts on this device or open the app settings and tap the account.
  3. Tap Server settings.
  4. Check the incoming and outgoing server configurations:
    • Incoming (IMAP): Server should be set to your provider’s host, Port 993, Security Type SSL/TLS.
    • Outgoing (SMTP): Server should be set to your provider’s host, Port 587 with STARTTLS (or Port 465 with SSL/TLS).
  5. If the server uses an untrusted or self-signed certificate, Android will drop the connection without warning. Select SSL/TLS (Accept all certificates) only if diagnosing a known internal corporate server.