Skip to content

Incorrect line endings in outgoing SMTP messages #8806

@jennifer-richards

Description

@jennifer-richards

Describe the issue

As discussed a bit in the description of #8805, I believe the datatracker is incorrectly sending <LF> instead of <CRLF> as line endings. This is at odds with RFC 5321 (see in particular the third paragraph).

Poking at this, I found that removing the force_bytes() from

unhandled = server.sendmail(frm, to, force_bytes(msg.as_string()))
appears to resolve the issue. That uses the fact that Python's SMTP.sendmail() method translates bare <CR> or <LF> into the <CRLF> sequence when its input is a string. When that input is a bytestring, it sends the bytes verbatim.

At least for the text email case I was looking at, the message body coming in has been formatted with email.mime.text.MIMEText, which normalizes line endings to \n, so by the time we reach sendmail() we've already lost any special endings that could have existed. As a result,I believe that for this code path (starting at send_mail_text()), dropping the force_bytes() is a reasonable change. There are many other ways these methods are called, though, so more investigation is needed.

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions