shawwwn/uMail

UTF-8 support

crysman opened this issue · 4 comments

First of all, thanks for this library.

Unfortunately, we cannot use it in our e-mailToSMS use case, since the phone provider requires e-mails being in UTF-8 in order to allow "forwarding them to SMS" (see below). There must be something like Content-Type: text/plain; charset=utf-8 missing in the e-mail headers, because there is no content-type whatsoever.

Any proposal how to fix this easily? Thanks a lot.

Here is the e-mail returned with censored IPs and phone number:

<[CENSORED_PHONE@sms.t-mobile.cz](mailto:CENSORED_PHONE@sms.t-mobile.cz)>: SMTPUTF8 is required, but was not offered by host
    CENSORED_IP[CENSORED_IP]
Final-Recipient: rfc822; [CENSORED_PHONE@sms.t-mobile.cz](mailto:CENSORED_PHONE@sms.t-mobile.cz)
Original-Recipient: [rfc822;CENSORED_PHONE@sms.t-mobile.cz](mailto:rfc822%3BCENSORED_PHONE@sms.t-mobile.cz)
Action: failed
Status: 5.6.7
Diagnostic-Code: X-Postfix; SMTPUTF8 is required, but was not offered by host
    CENSORED_IP[CENSORED_IP]

well, it's likely not about having "UTF-8" in headers - I've just send another one from Powershell and it has this in headers:

Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

no "UTF-8".

Anyways, the e-mail sent from the ESP32 device using latest actual MicroPython contains no Content-Type nor Content-Transfer-Encoding - that might be the problem (?)

I think headers such as Content-Type is to be defined inside the mail body using .write() method.

adding

        smtp.write("Content-Type: text/plain; charset=utf-8\n")
        smtp.write("Content-Transfer-Encoding: quoted-printable\n")  

has not helped. It is, indeed, present in the e-mail header, but I'm still getting Undelivered error with Diagnostic-Code: X-Postfix; SMTPUTF8 is required, but was not offered by host.

I've found out that when I ommit all diacritics from Subject and/or from Body, it works correctly... (special characters can be used in body, that works OK, only subject is problematic)

Nobody has encountered this problem yet? I believe there must be plenty use-cases when some characters like ěščřžýáíéüůú are used, right?

OK, so far, I am just exitting upon detecting problematic characters

if (re.search('[^a-zA-Z0-9_-\ ]',subjectStr)):
    print("ERR: subject cannot contain special chars due to 'X-Postfix; SMTPUTF8 is required, but was not offered by host' error")
    sys.exit()

I wanted to encode the subject like https://www.sendblaster.com/utf8-email-subject-encoder/ but I could not find base64 encoding for mycropython :(

But, we might close this with a workaround "do not use any special characters in subject".