This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: smtplib.send_message mishandles 8BITMIME RFC 6152
Type: behavior Stage: patch review
Components: email, Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Segev Finer, barry, r.david.murray, scorphus
Priority: normal Keywords: patch

Created on 2018-02-10 10:46 by Segev Finer, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 8303 open Segev Finer, 2018-07-16 19:50
Messages (7)
msg311947 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-02-10 10:46
According to https://tools.ietf.org/html/rfc6152 you should only send an 8bit email body when the server advertises 8BITMIME in the EHLO, and you should declare it with BODY=8BITMIME in the MAIL command.

The default cte_type is 8bit for the new default email policy which is what will be used by smtplib.send_message when it calls BytesGenerator.flatten, but it will not set BODY=8BITMIME even if the message has any 8-bit characters. It will only set BODY=8BITMIME if the message uses any utf-8 mail/from addresses. This means that a message with ASCII addresses and an 8-bit utf-8 body will be sent without BODY=8BITMIME (I think that's actually quite common).

What should be done is checking if the server advertises 8BITMIME, and if it doesn't use cte_type=7bit; if it does we should set BODY=8BITMIME if the policy is using cte_type=8bit.

I don't know whether any real email server chokes on this. But it's best to follow the RFC, I think.
msg311960 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-02-10 21:03
I agree.  I'll be happy to review a patch proposal.  Not sure how I overlooked this when I implemented send_message, but that was early enough in my reading of all the RFC that I may have just missed that detail :(
msg322428 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-07-26 14:06
OK, the #32663 test fix I mentioned in the review is merged.
msg322438 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-07-26 16:27
> OK, the #32663 test fix I mentioned in the review is merged.

Yeah. I already merged it in.
msg322442 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-07-26 17:34
Merged into the PR that is.
msg322543 - (view) Author: Pablo Santiago Blum de Aguiar (scorphus) * Date: 2018-07-28 11:24
This is just to note that I'm investigating this as part of the CPython sprint in EuroPython.
msg322582 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-07-28 18:03
@scorphus Note that I made a PR for this: PR 8303
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76995
2018-07-28 18:03:39Segev Finersetmessages: + msg322582
2018-07-28 11:24:07scorphussetnosy: + scorphus
messages: + msg322543
2018-07-26 17:34:19Segev Finersetmessages: + msg322442
2018-07-26 16:27:20Segev Finersetmessages: + msg322438
2018-07-26 14:06:13r.david.murraysetmessages: + msg322428
versions: - Python 3.5
2018-07-16 19:50:17Segev Finersetkeywords: + patch
stage: patch review
pull_requests: + pull_request7837
2018-02-10 21:03:10r.david.murraysetmessages: + msg311960
2018-02-10 10:46:21Segev Finercreate