Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Limit Number of IMAP connections to Mail Server ...?

Greetings,

My host is complaining that Mail's IMAP opens too many connections (and keeps them open too long)... which is causing some issues on the hosting end.

Is there any way to limit the amount of connections Mail makes?

IMAP-IDLE is already turned off on all the accounts.

mini, Mac OS X (10.6.4)

Posted on Aug 17, 2010 9:59 PM

Reply
Question marked as Best reply

Posted on May 17, 2017 8:33 AM

I'm familiar with this problem for years, but to read here that it goes back over a decade unaddressed?! Wow! Here's the solution that's been working for us in shared hosting environments running linnux. It's pretty involved, technically, but we were in a situation where I couldn't be asking people to switch from Apple Mail to some other client.


via PHP on you hosting server run command line:

shell_exec("ps aux");

This will return a list of all your active server cinnections. It takes some effort to decipher, but included in it are things like what time the connection was initiated, the type of connection, and the all important PID number. Hosts can return this info in a variety of formats, and they can even evolve over time as your host upgrades their system, so you have to learn your hosts particular patterns.


You'll want to figure out which are the IMAP connections. Generally not hard to spot. Look for "imap".


Use grep if you need to limit the list, possible eg:

shell_exec("ps aux | grep imap");


(your needs may require a different grep)


The goal is to use this to generate a list of imap connections that are no longer active, which generally means imaps over a few seconds old (unless you're sending or receiving a large email or batches of emails and it's taking forever). So say any imap connection older than a minute or two. Get its PID and run the command line to kill it.


exec("kill -9 [PID]");



Algorithm:

Get all old IMAP connections

Kill them

Automate all of that and run on an interval, every minute.


I suspect a cron job is a good solution, but we use a web page so we can monitor the process in a browser. Wrap it hiwever you want


It resolved the issue for us for the last few years. Every so often the computer runing this code gets reset, and this routine is stopped, and sure as apples rot, our server laments too many connections and even blaclists our IP. So that's the hoops we jump through because Apple Mail can't kill old connections.


If you tell me that's crazy involved, you have my sympathy. We have yet to find a saner solution.

63 replies

May 15, 2011 2:52 PM in response to JoeWMpls

JoeWMpls, you're completely right, this is a very old problem... and Apple now is only about selling iPhones and iPads and MacBook Air with a future OSX (Lion) where the bullets in the dock aren't even there so the users that come from windows don't freak out with the concept of closing a window and leaving an app running...


It's bad... this is an old and boring problem... nobody is using POP3 anymore... it doesn't even make sense... the world now is all about "could" and data in a server available across multiple devices...


***?!? Steve it's a ******* **** socket...! It's not hard to close them or use the same! for god sake!

Jun 29, 2011 2:52 PM in response to badtz

another person affected by this. I have noticed that apple are quite active on these discussion boards... When the problem is the users fault. When there is a big issue that is perhaps down to them, they go completely quiet. Its diabolical that they cant just make Mail close its bl**dy connections when its not using them.

Jul 4, 2011 4:01 PM in response to badtz

I discovered this issue once we moved to HostGator. I've already switched hosts enough, I'm not moving my company's e-Com site once again just because of an email client problem. Because of this issue I've had to move to Outlook.


Unfortunately, Mail's prolific connection habit made me paranoid, especially after my site was blocked for half a day and I ended up creating most of the email accounts as POP3, which is fine as I oversee them. But, it just means that now I have to migrate everything from POP3 to IMAP, assuming MS didn't screw up Outlook like Apple did Mail. My biggest problem is that I can't even use Mail on the iPad to check my business email as I don't want to create POP3 accounts on a device with limited storage.


I can't believe that after all this time Apple *still* hasn't fixed this issue. Maybe with Lion? Anyone have a Preview version that can let us know if Lion's Mail.app fixes this issue?

Jul 4, 2011 4:19 PM in response to Richard Schwalb

Hi Richard,


Yep that a really crappy problem, since I'm a beta tester I've been sending emails to Apple since Leopard's first beta and even now with Lion I sent another email asking to solve this issue but they keep saying that it's a know issue and the engineering team is over it... but in the last years they didn't do anything at all.


I was hoping that with iOS and Mail for iPhone they solved this but not even that time.

Today the bug is still present in the last version of Lion. Sorry.


Last time I email them I got this (like all other times):


Hello,


After further review it has been determined that the feedback you provided is known to engineering and a solution is currently under investigation.


Thank you for reporting this.


It's a shame really...


In the overall Apple is not interested in the professionals and in their needs see Final Cut Pro X? See XServer and OSX Server? I'm really starting hate Apple. And... by the way, the workflow in Lion is very slow, too much eye candy and the "fast moving windows around in Spaces" is now a pain in the *** with Mission Control...

Safari is slower than ever and crashing with flash and facebook and the system is really heavy in a Core 2 Duo 2.5Ghz 8GB of RAM machine, the computer is always with the fans turned on just to browser two or three websites and mail.


God **** it Steve, if you don't have any more inovation to do just don't make the system look like a crappy buggy windows.

Jul 5, 2011 12:23 PM in response to iTCB13

Hi iTCB13,

That's really a shame to find out. I don't mind Outlook, but as I rarely use the rest of the MS Office Suite it seems such a waste. Plus, I can't check my company email from my iPad unless I want to go into cPanel and kill the connections once I'm done. Which, honestly, is a huge pain.


Looks like I'll be looking to migrate all my POP3 accounts in Outlook to IMAP, no Mail.app anytime soon. I'd use Thunderbird/Postbox, but that's for my personal email.


Thanks for the heads up, greatly appreciated.

Jul 5, 2011 12:48 PM in response to Richard Schwalb

Hi Richard,


I've had that problems with HG before, lucky now and since my company sells network services, including hosting, I'm not a HG client anymore.


Anyway, there are two options to go around your problem, the first one is simply use Outlook or much mcuhhh better Thunderbird for Mac (yes they do sockets right!) 😉 also... the very nice PostBox, I really love that program 😉


Other solution I never tried is to write a little PHP script that works like this:


1st - Check if the website is online

2nd - If is NOT online keep running, else exit

3rd - Login to cPanel

4th - Kill all IMAP connections


Then place this file in your host, out of the public_html folder (just security) and set up a cron job to run that every 5 minutes... That's a way to go it probably will work fine.... Just check if the PHP still runs after all IMAP connections are used 😉


Have fun 😉

Jul 5, 2011 1:02 PM in response to Csound1

Hi Csound1,


You're true about that, but it's a very high unnecessary server load, in my company we deal with others using Mac Mail and now we've the servers just killing old unused sockets because otherwise we would run out of ports ahah lol


It's really a pain in the *** the server load caused by Mac Mail... 😟 They should really fix that problem....

Nov 27, 2011 9:31 AM in response to badtz

Well, I have always wondered why I have three or four IMAP logins for each user on my Mac OS X Server. This is covered pretty good on a NewGator discussion:


Mac Mail leaves one connection open for each IMAP folder, that is, INBOX, OUTBOX, TRASH, and any custom folders you may have.


So once users started getting iPhones and iPads in addition to their MacBooks, that number increased.


While not a great solution, it explained rather clearly to me what was going on. Hope it helps.



http://support.hostgator.com/articles/specialized-help/email/mac-mail-setup


The text part you want to read:


Too many [email] connections, 500 errors? Here is a fix.


Thunderbird is normally the route I suggest, however the main problem with Mac Mail I've seen is with the IDLE setting, basically this leaves the connection to the server open to check for new messages as soon as they arrive rather than trying to connect every say 5 minutes or so.


NOTE: Before this fix will work, you may need to kill your hanging processes. You can simply ask HostGator to kill all of your current processes.


This link describes the setting and how to change it in Mac Mail: http://email.about.com/od/macosxmail..._imap_idle.htm


And I'll copy the relevant parts here:


To have emails appear instantly in IMAP accounts in Mac OS X Mail:


Select Mail | Preferences... from the menu.

Choose Accounts.

Select the desired IMAP account.

Go to the Advanced tab.

Make sure Use IDLE command if the server supports it.

You can additionally uncheck Include when automatically checking for new mail. Keep in mind that Mac OS X Mail receives instant updates only for the open folder, though.

While this may be the desired affect, to get your emails instantly, Mac Mail leaves one connection open for each IMAP folder, that is, INBOX, OUTBOX, TRASH, and any custom folders you may have.


My simple suggestion: Turn off the IDLE function and set it to check every 5 minutes or longer, and monitor your connections.

Jan 3, 2012 9:23 AM in response to timoto

Has anyone written Apple directly for assistance? My protection plan is no longer good so they want me to pay to get an answer on this. I can't believe it's gone on this long without a resolution. Come on people. My host wants me to delete my IMAP accounts and just foward all my accts to one catch-all gmail acct. How dumb is that? I am the admin to many websites, how unprofessional will it look if I'm responding to inquiries with one generic gmail acct for all of them? There's got to be a resolution other than this and switching hosts, please.

Limit Number of IMAP connections to Mail Server ...?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.