I'm running macOS High Sierra 10.13.4 on a 2009 iMac. I've got the screen set to go to sleep after 1 hour, and the computer to never sleep (it's running Indigo, jabberd, iTunes, and Server, so I don't want it to sleep, ever).
The computer never appears to sleep -- I can access my services regularly, even after not having touched the machine for days.
However, Mail does appear to sleep. I've got several rules set, and I can tell that Mail has snoozed off when I open Mail on my iPhone or iPad and see a ton of messages in my inbox that should've been filed elsewhere.
I can SSH onto the system, and can do anything I like, but while the system is awake, the Mail app doesn't wake up. I go back to the iMac (even remotely through a shared desktop) or move the mouse or tap on the keyboard, and *poof*, the messages get filtered properly -- as observed on iOS, remotely. Mail has awoken.
I've tried setting the following:
defaults write com.apple.mail.plist NSAppSleepDisabled -bool YES
and while I first thought it might be working, was proven wrong today.
pmset -g assertions
shows that PreventUserIdleSystemSleep is set to 1 and NetworkClientActive is 1, too.
shows that the system is prevented from sleeping by a ton of serverd processes.
What am I missing? Is Mail really going to sleep? Does it have some other strange mode it can get into that will prevent it from running its rules?
Try disabling App Nap altogether
How is Mail > Preferences > Settings > General > Check for new messages set? It's possible that "Automatically" includes some logic that results in "but not so obsessively unless we know the user is around" or some such. Perhaps setting it to a fixed interval would help?
Failing that, what about running `caffeinate` from the Terminal to ensure the system remains awake?
Don't want you to think I'm not responding -- I've tried @datafornothinandbitsforfree's suggestion to disable AppNap system-wide, and not had another recurrence since then. However, another variable has changed, in that I've wound up using the system multiple times a day since implementing that change. So, I've changed 2 variables, hence the test results are inconclusive.
I'll report back after this batch of tasks is done and the system usage has quiesced again. If this doesn't work, then I'll try Dave's suggestion (and yeah, it's currently set to Automatically.)
I've been waiting to post this just to make sure that the problem's truly gone. I've not had the system go back to sleep since I made the last change over a month ago. The problem was recurring at least weekly.
The change? Simple: I had originally set the iMac to wake up every day at 5AM. (Preferences > Energy Saver > Schedule... > Start up or wake = Every Day 05:00 AM.
I turned that off, and no more problems.
Bizarre, but true. That was the only setting change I made. I don't think I'm going to bother testing by turning it back on again, unless someone's really, really interested in the results...