Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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
Question marked as Best reply

May 17, 2017 8:33 AM in response to badtz

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.

Sep 24, 2010 12:45 PM in response to badtz

Bump - I am facing exactly the same issue. I have set up 6 accounts with my hosting provider for my whole family, and because of Mail.app behavior it creates 20+ connections and causes my hosting site to refuse new connections and takes out my personal website.

Is there a way to make the connections not persistent? Or to limit the maximum number of connections to a single server?

Sep 24, 2010 5:00 PM in response to badtz

I am also having this issue. IMAP IDLE is checked in advanced settings, but it is greyed out. I need to be able to limit the number of connections, or some way to make it close the connection when it's done getting new messages. I have dialed back the check-mail interval to 30 mins from 5 mins, but that hasn't helped any.

Oct 19, 2010 4:55 PM in response to badtz

I'm going to bump this as well. This started for me back in August; the net effect then was that one of my two desktops running Mail could not connect (I have one machine that does things like act as a SpamSieve drone) and my wife couldn't get her mail, either.

I thought the problem was a change at the web host, but they said "no." Not believing them, I switched my site and my wife's to a different host and the problem continued. Actually, it got worse, because my personal website (running Drupal) would go down. The new host identified the problem as being too many connections (processes) open to the server.

I stopped using IMAP-IDLE with no change in behavior.

(There's a key in com.apple.mail.plist that controls this setting:

<key>UseIDLEIfAvailable</key>
<string>NO</string>

If that key is missing the Use IDLE If Available checkbox will be disabled. I don't think adding it will make a difference, but you could try.)

I also disabled notes and todos for each account (so the Apple Mail To Dos mailbox doesn't get created) and changed each account on my SpamSieve drone so that the Junk mailboxes were created on the Mac. That meant two fewer open mailboxes for each of four different accounts... but I still have too many connections open on my hosting account. (I also disabled the accounts on my iPod and iPad.)

Would appreciate any more suggestions before I switch to a completely different email client. (Taking suggestions for that, too.)

Nov 21, 2010 11:13 AM in response to badtz

BUMP

Agreed, Absolutely ridiculous that this has not been addressed. I guess it meets Apple's sales model. Mett the average consumers needs and wants, but ignore any advanced need. I am under the assumption that, even though IDLE is SUPPOSED to do something, it doesn't make a difference in the number of connections, at all. This has been tested on two totally different host, and one controlled and maintained by a family number. The amount of connections Mail makes per account is out of this world and causes server wide problems.

I actually changed hosts and moved websites to address this problem and not have to resort to Thunderbird. I say resort, not because it is bad software, but because I want to all of my Apple software and hardware to play nice together, as all of us do, and is the reason most of us spend 2x$ for Apple gear. I had to move all of my accounts to Thunderbird again because my new host (HostGator) will shut my sites down while the two computers in my office access 4-5 accounts each.

I have visited and re-visted the Apple forums over the last couple years, waiting for a solution. I can't believe this. I guess I'll join the petition now. I feel bad for the people out there experiencing these issues, having no clue what is causing it, how to research it, or what to do about it.

Apple, please just fix it.

Dec 3, 2010 2:15 AM in response to JoeWMpls

I've been having this very same problem since I started accessing my IMPA accounts from my iPhone and iPad on top of my Mac, and it seems I'm going to have to try and find a new host, since they don't offer any solution.
You said you switched host, does the new one solve the issue? If so, what company is it?
Thanks.

Dec 3, 2010 4:48 AM in response to JoeWMpls

What are the number of connections being cited? I have eight IMAP accounts (and 7 POP) accounts, four of which are with my hosted accounts with DreamHost, plus one with MobileMe, Gmail and AOL. I have not gotten any feedback as to any problems. Apple as the provider of MobileMe IMAP accounts should see the same thing any other provider sees, one would think?

I do know that Mail 4.x checks the connection with the SMTP on a regular basis, even if the SMTP is not currently used by any account, but this is not limited to IMAP, and is not controlled by the frequency of checking for new messages.

More info, please.

Ernie

Dec 3, 2010 4:53 AM in response to Ernie Stamper

I just know, from the mail server logs that my hosting company (lunarpages) provided that the connexion limit is exceeded... I'm using about 9 IMAP accounts (each on different domains linked to the same host account) on my MacBook Pro, my iPad and my iPhone. The problems occur when all these devices access the IMAP server from the same wifi network, i.e. using the same IP address...
Here are the limits that I was made aware of by my host:
100 Maximum IMAP Connections
15 Maximum IMAP Connections Per IP
15 Maximum TLS/SSL IMAP Connections Per IP
Number of Authentication Daemons 5
I have the problem whether I use SSL or not, so it's not related to that... it's probably the 15 IMAP connections by IP and/or the 5 authentication daemons.

Dec 3, 2010 9:43 AM in response to m::se

During what span of time? Without that info, these limits seem ridiculously low. The nature of IMAP is that the mailboxes/folders reside on the server and not on the computer. Thus simply using the email client requires connection. Unless another email client "holds" the connection, and use doesn't show up as a new or renewed connection, I don't see why Mail would be different?

Ernie

Dec 3, 2010 2:54 PM in response to m::se

Interesting discussion unrelated to Mail or to Macs at:

http://www.google.com/support/forum/p/gmail/thread?tid=56a00af6e404cc7f&hl=en

also, at:

http://serverfault.com/questions/176494/options-for-proxy-ing-a-connection-limit ed-imap-account

I also note that while use of the IDLE Command may mitigate this problem, the server must capable:

http://kb.mozillazine.org/IMAP:advanced_accountconfiguration

Also issues with Outlook discussed at:

http://thedailyreviewer.com/outlook/view/maximum-number-of-server-connections-on -imap-server-101577860

As far as HostGator, the problem seems to be as much with their specs, as with Mail?

http://forums.macrumors.com/showthread.php?t=965587

Btw, I connect with my IMAP accounts either with three computers, or two computers and my iPad. I guess my providers are not using Courier servers?

Ernie

Message was edited by: Ernie Stamper

Feb 8, 2011 4:38 PM in response to Michael Meiners1

Sad as it is, the only solutions I can find to this issue are:

1. Switch hosts. Ouch.
2. Switch email clients to one that lets you limit the number of open IMAP processes. Ouch.

Seems to me that the blame here rests on both Apple and the host (Hostgator and Bluehost are known to have this issue). Apple could put in a setting to let you limit the number of IMAP processes. Your host could support the IDLE command, which it seems these ones do not.

Instead, these hosts limit you to 25 simultaneous processes, which becomes limiting pretty quickly at 4 constant processes per IMAP account per device (the iPhone adds 4 more per account). One person with two accounts checked by both Mac Mail and iPhone can eat 16 or 25 processes by themselves. Next thing you know your site is down or someone can't get their email.

What you CAN do is submit feedback to Apple about wanting the option to limit processes in Mail, although they are no doubt aware of the issue and don't care. I've seen several references to people submitting this issue to Apple years ago and nothing's happened so far. My guess is they'd point to the host for not supporting the IDLE command and the host would point to Mac Mail for not letting you limit connections.

May 15, 2011 2:45 PM in response to badtz

This is a serious problem with Mac Mail... In my company we use iPhones and some Macs as IMAP clients and in my server there's a lot of unused IMAP connections opened all the time.


***?! This a is a 7 year problem!!! Just make it right... it's not hard to control open sockets for god sake!


Did someone got a solution? Other than thunderbird... because thunderbird can do it right... one connection per email address and thats it.


Thanks!

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.