[
    {
        "role": "user",
        "content": "mbsync%20cannot%20connect%20to%20imap.gmail..com%20connection%20timed%20out"
    },
    {
        "role": "assistant",
        "content": "If you're getting the error `mbsync cannot connect to imap.gmail..com connection timed out` (or something similar), here are several troubleshooting steps and a sample configuration that commonly fixes the issue. Let\u2019s walk through the likely causes and remedies.\n\n---\n\n## \u2705 Check Gmail Requirements\n\nBefore diving into `mbsync` configuration, make sure:\n\n1. **IMAP is enabled in Gmail**  \n   Go to Gmail \u2192 Settings \u2192 \u201cForwarding and POP/IMAP\u201d tab \u2192 Enable IMAP. ([ccgit.crown.edu](https://ccgit.crown.edu/cyber-reels/gmail-imap-settings-password-configuration-guide-1767647439?utm_source=openai))\n\n2. **Use App Password if 2-Step Verification is on**  \n   If your account has 2FA, using your normal password may be rejected. Generate a 16-character app password and use that in your `mbsync` config. ([gaintools.com](https://www.gaintools.com/cloud-migration/setting/?utm_source=openai))\n\n---\n\n## \ud83d\udee0 Network and SSL/Port Issues\n\nTimeouts often happen when:\n\n- The wrong port or SSL/TLS configuration is used.\n- Your firewall or network is blocking the port (usually 993 for IMAP over SSL).\n- `mbsync` is using IPv6 but there's no proper IPv6 connectivity.  \n\nGmail supports SSL/TLS on port 993 for IMAP. Plain-text IMAP (port 143) requires STARTTLS, which is less commonly used with Gmail. ([developers.google.com](https://developers.google.com/gmail/imap/imap-smtp?utm_source=openai))\n\n---\n\n## \u2699 Sample `.mbsyncrc` Configuration Working for Gmail\n\nHere\u2019s a minimal working configuration that many users report works well:\n\n```ini\nIMAPAccount gmail\nHost imap.gmail.com\nUser your.email@gmail.com\n# If using 2FA, this is the App Password from Google\nPass your_app_password_here\nPort 993\nSSLType IMAPS\n\nIMAPStore gmail-remote\nAccount gmail\n\nMaildirStore gmail-local\nPath ~/.mail/gmail/\nInbox ~/.mail/gmail/Inbox\nSubFolders Verbatim\n\nChannel gmail\nFar :gmail-remote:\nNear :gmail-local:\nCreate Both\nSync Pull\n```\n\n**Key parameters to verify:**\n\n- `Host` must be `imap.gmail.com`\n- `Port` must be `993`\n- `SSLType` must be `IMAPS` (sometimes \u201cSSL\u201d in older configs, but IMAPS is the correct modern value) ([reddit.com](https://www.reddit.com/r/emacs/comments/177v094?utm_source=openai))\n- Use the **App Password**, not normal password, if 2SV is active ([gaintools.com](https://www.gaintools.com/cloud-migration/setting/?utm_source=openai))\n\n---\n\n## \ud83d\udc1e Specific Errors and Known Bugs\n\n- `Socket error on imap.googlemail.com (\u2026:993): timeout`  \n  This has been reported as a DNS or IP caching issue in `mbsync` state files. One fix is to delete `~/.mbsyncstate` so it re-resolves the hostname. ([sourceforge.net](https://sourceforge.net/p/isync/bugs/60/?utm_source=openai))\n\n- `unexpected EOF from imap.gmail.com \u2026 error:0A000126:SSL routines: \u2026`  \n  This is from Gmail closing socket before TLS close notification. A newer version of `mbsync` handles this more gracefully. Updating to latest version helps. ([bugs.launchpad.net](https://bugs.launchpad.net/bugs/1995690?utm_source=openai))\n\n---\n\n## \ud83e\uddf0 Troubleshooting Steps\n\nTry these in order:\n\n1. **Check internet connectivitiy to `imap.gmail.com:993`**  \n   Run something like `telnet imap.gmail.com 993` or `openssl s_client -connect imap.gmail.com:993` to see if port is reachable.\n\n2. **Delete the sync state file**  \n   Remove or rename `~/.mbsyncstate` to force fresh DNS resolution. This solves stale IP issues. ([sourceforge.net](https://sourceforge.net/p/isync/bugs/60/?utm_source=openai))\n\n3. **Update `mbsync` / `isync` to latest version**  \n   Especially on Linux distros where packages lag behind, updating can include fixes for SSL and timeout bugs. ([people.kernel.org](https://people.kernel.org/mcgrof/replacing-offlineimap-with-mbsync?utm_source=openai))\n\n4. **Check SSL CA certificates**  \n   Sometimes local CA bundle is outdated or missing, causing SSL handshake failures. Ensure your system's CA store is current. ([reddit.com](https://www.reddit.com/r/openSUSE/comments/f2i61d?utm_source=openai))\n\n5. **Check for IPv6 vs IPv4 issues**  \n   If your system has IPv6, try forcing IPv4 (sometimes via config or `Host` resolution) to see if that helps.\n\n---\n\nIf you like, I can help tailor a config for your system (e.g. distro, version of `mbsync`) to ensure it works. Do you want to go through that?"
    }
]