If an email has a super long subject header (for example) with no spaces in it, email delivery can fail.  For example exim gives message has lines too long for transport
We’ve handled this before:
- in SMTPClient.sendmailandtest_send_email_long_lines_use_quoted_printablebut apparently it doesn’t split a header if there’s no spaces or other chars to split on
- encode_email_parthandled it too, and debugging that seems like it works correctly (setting header charsets) but it still ends up rewritten later in sendmail, and causes the error
https://docs.python.org/3/library/email.mime.html for MIMEText and MIMEMultipart extend from Message which has a default policy of compat32 (python 3.2 compatibility, bugs included).  Specifying a different policy (or using EmailMessage perhaps) seems to work better, and maybe we can get rid of workarounds within our code.  See https://docs.python.org/3/library/email.policy.html in the middle of the page. SMTP seems best.  (SMTPUTF8 sound appealing, but not all mail servers support utf8)