Resolving "There is a problem with your mailboxes." in El Capitan I'm running into an identical problem with Mail on two separate systems, both starting immediately after upgrading from a long-working Yosemite to the new El Capitan and persisting through the latest 10.11.2 version.  The systems have at least 16GB of memory and well over 200GB of free disk space, no other apps are running, nor does Mail have any extensions installed.

The problem manifests with Apple's Mail, even while unattended, at some point spontaneously popping up with this error in a dialog box:


  There is a problem with your mailboxes.
  
  Try clicking Quit and then opening Mail again. If this message
  reappears, click Quit and Rebuild Index. The next time you open Mail,
  it will import your messages.


The only options are Quit and Quit and Rebuild Index. Neither resolves the problem for future invocations.

Connection Doctor shows all connections (SMTP and IMAP) as green, in fact the Show Details panel continues to show what looks like active and good communication even after the model error box appears, this includes "OK Still here" idle responses.

Activity monitor usually continues, but sometimes halts while Download Messages. Mail will often peg at 99-100% CPU.

Console will issue these messages, but nothing more descriptive:


Mail: Error accessing account, (null)
kernel: process Mail[###] thread ##### caught buring CPU!; EXC_RESOURCE suppressed due to audio playback
com.apple.xpc.launchd: (com.apple.xpc.launchd.oneshot.0x10000005.Mail[###]) Service exited with abnormal code: 1


Note there is no sound being played, so I don't know what the audio playback would be.

I have tried:


Rebooting
Safe Rebooting (holding down Shift at boot)
Using Disk Utility to verify the disk
Repairing Permissions in El Capitan
Launching Mail in safe mode (holding down shift when starting Mail)
Using nearly every aggressive feature in Onyx
Taken all accounts offline and online, incrementally from the Mailbox menu
Disabling and re-enabling the email account(s) from Mail Preferences...
Deleting and re-adding the email account(s)
Discovered it happens with even just one account, regardless of which
Resyncing the accounts, from the Mailbox Menu
Rebuilding the accounts within Mail
Reindexing the accounts by deleting the Envelope Index files and letting it download all content again
Removing Mail's saved state
Remove and Rebuild mail's container
Vacuuming Mail's index, though used V3 instead of V2


Can anyone suggest something else to look at or try?

An interesting possible clue:

In Mail's Connection Doctor it is possible to check Log Connection Activity, and then Show Logs.  In the YYYY-MM-DD_Library.log file, I'm seeing something that smells highly suspicious.

Mail[###] &lt;Debug&gt;: SQLite error 7 (out of memory): Error preparing statement for query SELECT ROWID, remote_id, flags FROM messages WHERE remote_mailbox = (SELECT ROWID from mailboxes WHERE url = ?) AND remote_id IN ( ...a huge list of integers, at well over a hundred thousand, appear here ... ) ORDER BY remote_id

It is true that the server this connects to has multiple years of messages, though they are spread across about three dozen mail folders.

Open to ideas to try.
I too am having this issue since upgrading to El Capitan in October. It is quite frustrating as any email being composed is lost once the error dialog box hits. 

The only partial work around I have found is deleting the log files found at:
\library\containers\com.apple.mail\Data\library\logs\Mail*.log

Mail seems to keep writing to these log files, using more and more ram in the process, until mail becomes unresponsive and the error dialog appears.