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

Jan 12, 2012 6:00 AM in response to hoaxnheimer

No Apple solution so far as I'm aware of.


The first thing is to make sure as few emails as possible are in the top level "Inbox". Users need to have their email put into "sub-folders" per project or whatever catagories make sense..


However, when sub-folders with lots of mails are opened the number of IMAP connections rises.


It kind of kills the point of "smart mailboxes" as you end up having to maintain a fixed folder structure and possibly more mail filtering for those that can't be bothered to manually move their mail into sub-folders.


The only way to kill the number of connections from the client end is to quit mail.app and start again.


From the server side connections can be killed with a command that could be put into an automated cron job. However if the users need to access greater numbers of emails on a constant basis, then the problem will not be resolved.

Jan 12, 2012 6:06 AM in response to badtz

Aloha,


i really cannot seriously tell all our employees to restart their mail-clients all the time 🙂


neither i can tell my bosses to user thunderbird or anything else due to the fact, that they spend a lot of money in buying M$ Office licences


In addition i do not have any access to the IMAP Server since its a hosted service.


Since i am very new to this community, does no one from the Apple support team read or comment this kind of conversations?


grtx

Jan 12, 2012 6:13 AM in response to hoaxnheimer

I completely agree with you, it's quite ludicrous, but these seem to be the options.


By the way just because it's a hosted service doesn't mean you can't have some sort of cron job running. Ask the provider. But really I don't find this to be an acceptable solution myself.


I found the proceedure that gave best results was to get mail out of the Inbox. Keep it under 500 mails.


Apple do check these posts sometimes but if you want to you can report a bug, I think many of us have done so, but as you can see, to no avail. 😟

Feb 25, 2012 3:58 PM in response to badtz

In response to the "this affects my poor company"-type replies: Fact is, this is what you get for using free/discount email bundled with your cheap web hosting plan. Keep your web hosting, but move email to a real email host and these issues will be a thing of the past.


Sure it would be nice if Apple would include an option to limit IMAP processes, but it's not likely going to happen and I don't see it being their responsibility. Hostgator's (and many other hosts) practice of counting negligeable IMAP processes against your simultaneous process count is weak, but really mail is just a free add-on to their discount web hosting. That's not Apple's problem.


If email is important to your company, then it's worth more than the nothing you're probably paying for it.

Mar 16, 2012 4:44 AM in response to Rey Mo

Aloha,


@Rey Mo - why this disrespectful?


It is not about "poor company" discussions!!


Its about that we pay for something which does not work properly, apart from tons of spent hours in researching, trying things out, which are somehow documented standards and just do not work, because of that kind of software behaviour.


I did not want this, but now we use Microsofts "office 365" services.

Mar 16, 2012 1:00 PM in response to hoaxnheimer

@hoaxnheimer:


I was not being disrespectful. A bit blunt maybe, but only because some of the people posting here clearly need this wake-up call:


If you have a business and email is important to it, then you are doing your company a disservice by using the free email hosting bundles with your discount web hosting. That's the real problem. Even if Apple changes Mail to let you limit IDLE IMAP processes, this would only serve to accomodate weak email hosting and there are still real reasons that the cheap/free email option is a poor decision for your business.


We live in a time where constructive criticism is increasingly viewed as mean or disrespectful. I see that as a problem because I know that I'm not above criticism. Anyone who has ever run a business will at some point do something silly (like rely on a free email add-on to their discount hosting plan). If someone gives advice that helps correct a poor decision - even if it stings - a good business owner will have an "aha" moment and correct this ridiculous behavior, as you did by going to Office 365.

Mar 28, 2012 4:55 PM in response to hoaxnheimer

Just came across this while looking for a solution for my small office, I though I was going crazy for a moment.

I am a one man show that just set his home studio and of course I went with the cheapest possible plan for hosting and the rest, only me for now, don't need anything more.

IMAP connections is a big problem for me since I'm with Hostgator and after reading and trying different setting and email apps for the mac, I found the perfect solution, "Postbox", very nice email app that allows you set how many connections are open for IMAP, mine is set to 1 and problems are gone, Mail app keeps opening connections for cache purposes. Like someone mantioned is free and shouldn't be expecting much out of it.

Postbox (on the App Store) is way better than the Mail app, plenty of more options, specially when it comes to IMAP. It is not free but you get a lot more control, better organized.

I need to mention, I don't work for or have any relationship with Postbox or the authors of it, I just like it that much, and most of all, fixed my issue witht the Mail app and IMAP connections. Hope you guys find this helpfull.


M

Jun 25, 2012 3:05 PM in response to badtz

Just another Mail user who is requesting that the Mac Mail techs do something to fix this issue. PLEASE.


I have spent two days trying to find a solution after setting up several websites and emails with HostGator, recently, only to have all the sites shut down when Mail is running. Unchecking the "Idle" feature does nothing, as many have experienced. As Pointm suggested Postbox as a good alternative and I'm looking into it now. Unfortunately, they don't have an iPhone or iPad version, yet, and I'm a fan of total integration. For the meantime, I'm having to split my hosting with two different services, one for the websites and the other for emails. It's been a royal pain to have to do this, but I can't risk my sites shutting down.

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.