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

Dec 15, 2015 11:12 AM in response to badtz

The only way to go is to revert to POP and redefine your settings to leave a copy of the emails on the server.

I was livid with my ISP Siteground and spent a lot of time discussing the settings etc. They kept asking me to verify the server names an ports but it was the number of open sessions which kept killing the connection and prompt for password etc.

Nov 16, 2016 9:42 PM in response to badtz

Back in 2010 this issue was said to be 6 or 7 years old... so now it's over a decade. Great.


Worse now too thanks to Sierra not allowing you to disabled IDLE anymore.

I wouldn't mind idle at all btw, love the idea... but open one connection per account, not one per folder or whatever is happening here. Even for a real business user paying $400 a month for a managed dedicated server, if you have several accounts (diff domains) then you quickly go way WAY over 25 connections. One user I deal with frequently hits 80+. And it seems like there may be more going on too, because the number keeps growing. If it were just a matter of having 4 connections per account, it would at least sit stable at 20.


To the people who have described this as a non issue because connections are cheap and it doesn't matter how many you open... that's the same thinking that leads to 10MB apps that just do a simple function... and another app does the same thing with 300k. And that leads to a phone that fills up way too soon. Far from superior engineering as one fanboy claimed 3 years ago, that is naive junior engineering. And not giving people a choice in how to manage their resources... makes me picture a Shakespearean era noble holding their breath on the dais lest the foul breath from the stupid peons below may sully their superiority.

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.