Without doing that, it’s possible to force specific background colors on most email clients, the exceptions seem to be some of the older Outlook desktop email clients. (I’m guessing that dark mode doesn’t get that much use on desktop clients.)
For iOS (excluding Gmail) email clients, Discourse is already doing this if the apply custom styles to digest setting is enabled. The problem is that it’s hardcoding in the background color and not respecting the site’s “header background” color:
The [dm='header'] rule could be changed to:
"
[dm='header'] {
background: ##{ColorScheme.hex_for_name('header_background')} !important;
}
"
If it made sense, a similar approach could be taken for the “Since your last visit” section:
"
[dm='body_primary'] {
background: #{SiteSetting.email_accent_bg_color} !important;
color: #{SiteSetting.email_accent_fg_color} !important;
}
"
Note that the dm attribute for dark mode styles gets added to the email here: discourse/lib/email/styles.rb at main · discourse/discourse · GitHub.
Something like that should work to fix the issue on iOS (excluding Gmail) email clients.
For the iOS Gmail client, the background colors can be forced by setting them with a linear gradient. There don’t seem to be any unintended side effects of setting a linear gradient background in this way for all email clients. So it should be ok to just add a linear gradient background color to the inline CSS that’s sent to all email clients.
My suspicion is that the easiest solution for dealing with the “Since your last visit” section for email clients that perform a full color invert would be to just let the clients perform the invert, but make sure there is lots of contrast between the email accent accent bg color and email accent fg color settings:
That should prevent cases like this (with the default values of those settings):

