Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bug in smtplib example #120662

Copy link
Copy link
Closed
Closed
Copy link
@MordechaiFast

Description

@MordechaiFast
Issue body actions

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

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.