Skip to content

Commit

Permalink
Merge pull request #75 from miohtama/patch-2
Browse files Browse the repository at this point in the history
Fix lone \n in email as against RFC2822 recommendation
  • Loading branch information
digitalresistor committed May 15, 2021
2 parents 563d875 + 72f8d66 commit 19ddee6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pyramid_mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

from email.mime.nonmultipart import MIMENonMultipart
from email.mime.multipart import MIMEMultipart
from email._policybase import Compat32

from email.encoders import _bencode

Expand Down Expand Up @@ -484,6 +485,15 @@ def to_message(base):
for part in base.parts:
sub = to_message(part)
out.attach(sub)

# Message.policy tells how we format out raw ASCII email
# Lone \n is not allowed in email message, but
# Python generates this by default.
# Sparkpost SMTP would reject us as
# smtplib.SMTPDataError:
# (550, b'5.6.0 Lone CR or LF in headers (see RFC2822 section 2.2)')
policy = Compat32(linesep="\r\n")
out.policy = policy

return out

Expand Down

0 comments on commit 19ddee6

Please sign in to comment.