Closed
Description
Documentation
The example code is meant to demonstrate sending a multi-line message. It does not do that; the lines get contracted into one.
This can be fixed by adding a newline character to the end of the line when it is added to the message string:
msg += line + '\n'
BTW, why not use PEP8 compliant names, f-strings, and context managers? Why make things complicated with a .strip() call? Why make it that blank lines in the message are like pressing send?
import smtplib
from_addr = input("From: ")
to_addrs = input("To: ").split()
print("Enter message, end with ^D (Unix) or ^Z (Windows):")
# Add the From: and To: headers at the start!
msg = f"From: {from_addr}\r\nTo: {', '.join(to_addrs)}\r\n\r\n"
while True:
try:
line = input()
except EOFError:
break
msg += line + '\n'
print("Message length is", len(msg))
with smtplib.SMTP('localhost') as server:
server.set_debuglevel(1)
server.sendmail(from_addr, to_addrs, msg)
Linked PRs
Metadata
Metadata
Assignees
Labels
Documentation in the Doc dirDocumentation in the Doc dir