The server returned the error: The server “imap.gmail.com” cannot be contacted on port 993 My Mac Mail has just started going on the fritz.
I have a gmail account linked to mail and also a hotmail account. Both have warning signs and I cannot send or receive mail. They were both fine yesterday. I have not updated or changed anything.

I am running OS X 10.8.2 and Mail Version 6.1 (1498).

When I click on the warning sign for gmail to 'take it online' I get the following message:


  Unable to receive mail. There may be a problem with the mail server or
  network. Verify the settings for account “gmail” or try again.
  
  The server returned the error: The server “imap.gmail.com” cannot be
  contacted on port 995.


...And the following for Hotmail account:


  Unable to receive mail. There may be a problem with the mail server or
  network. Verify the settings for account “Hotmail” or try again.
  
  The server returned the error: The server “pop3.live.com” cannot be contacted on port > 995.


I've tried sending mail and it shows that both gmail and hotmail are both offline.

I have been on multiple forums with this problem and it seems the whole world is having the same problem with no fix. 

I've already tried the following to no avail:


I've checked all my info is entered correctly.
Changing the 'incoming mail server' to IMAP.googlemail.com - this got rid of the warning sign but still, will not send or receive mail. The warning sign has now changed to a 'zig zag' sign next to gmail.
Changing the port number from 995 to 993.
Re-entering my password.
Deleting the accounts and re-adding them.


Nothing works. Please does anyone have a REAL fix for this?

* Cant add this comment for some reason? But here we go:

Hi there,thank you for your fast responses. I have tried restarting my router and mail.app to no avail. Apologies - an error in my copy/pasting, the port for IMAP is 993. I just tried your terminal command and got the following:   imap.gmail.com: nodename nor servname provided, or not known. I just tried adding my gmail acc. on my sisters iPhone 5 and got the following: Unable to connect to SSL, would you like to try and connect without SSL? (Yes) and got this: The IMAP server 'imap.gmail.com'is not responding. Check your network connection and that you entered the correct information in the 'incoming mail server' field. Im sorry, I dont know what a VPN is.

Also, All of a sudden BOTH accounts just came back online and updated with new mails etc. I've 'essentially' not changed anything. I reset the app and the router well over 20 minutes ago prior to this. You'd think changes would be instant if that was the fix?
The canonical fix for troubleshooting Mail on OS X is to run the Connection Doctor (it's slightly buried in the Window menu without a keyboard shortcut to summon it) to isolate whether you have a general network error condition or a specific error on one or more of the accounts.

Each mail account will typically have two servers - different internet ports and potentially different username / password / authentication details.

Once you can isolate a specific error message on a specific port to a specific IP address, you can begin to troubleshoot whether you have a configuration issue, a network reachability issue or a server issue.

The show detail button is helpful to log the exact transactions and communications between Mail and the server.

If you have a vexing problem, I have found that disconnecting the network connection and quitting Mail (or forcing a reboot while the network is off) will let you start Mail and disable all Mail accounts except for one and also check for a stuck message or two in the Outbox. File those away as drafts so that you can then run connection doctor, re-enable the network and systematically work on the communication needed between the Mail program and your mail server.