pallets-eco/flask-mail

Flask-Mail failed to send mails with specific subjects

Closed this issue · 2 comments

For the reason of the unresolved Python issue http://bugs.python.org/issue27240
mail sending by Flask-Mail failed for some mail Subjects.
I.e. for subject: "i demandé comment il avait fait pour éliminer de la sorte trois adversaires dans un si petit espace et lui-même na pas su me dire."

Flask_mail makes different calls in method Message.as_bytes() for Python v < 3.4 and >= 3.4:

def as_bytes(self):
    if PY34:
        return self._message().as_bytes()
    else: # fallback for old Python (3) versions
        return self._message().as_string().encode(self.charset or 'utf-8')

I've taken above error only for PY34 branch (_message().as_bytes() called) and no error for old python branch (_message().as_string() called).

Temporary I've patched my flask_mail Message.as_bytes() to run always as_string().encode() for all Python versions (I've tested on 3.5.2). It is not guaranteed solution, but it is the one solution I've found to work.

It looks like subject lines must be in ascii with Flask Mail. Accent characters and other UTF-8 or UTF-16 characters throw it off. Thanks for posting this.

Minimum supported version is now Python 3.8. I can't reproduce this.