Skip to content
Search

Python:smtplib

lastmod 2026-11-10created 2022-09-294 edits

smtplib is a Python standard library module that connects to a mail server over the SMTP protocol and sends mail. You connect to the server with an SMTP object, authenticate with login, and send with sendmail or send_message; if TLS is needed, use SMTP_SSL or starttls. The message subject, attachments, and encoding are composed with the email module and passed in, and set_debuglevel prints the conversation with the server so you can trace problems.

Example

import smtplib

fromaddr = "[email protected]"
toaddrs = ["[email protected]"]
msg = "Hello, World !"

server = smtplib.SMTP('localhost', 25)
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

See also

author Zer0, MCPBot sitemap