Python smtplib Module
Example
Send an email using SMTP:
import smtplib
sender = 'emil@example.com'
receiver = 'tobias@example.com'
message = 'Subject: Hello\n\nThis is a test email from Emil'
print('Email prepared for sending')
Try it Yourself »
Definition and Usage
The smtplib module defines an SMTP client session object for sending emails using the Simple Mail Transfer Protocol.
Use it to send emails programmatically through an SMTP server, with support for authentication and secure connections.
Members
Member | Description |
---|---|
LMTP | LMTP client session object (local mail delivery). |
SMTP | SMTP client session object for sending mail. |
SMTP.connect() | Connect to an SMTP server. |
SMTP.ehlo() | Identify yourself to an ESMTP server. |
SMTP.login() | Log in to the SMTP server. |
SMTP.quit() | Terminate the SMTP session and close connection. |
SMTP.send_message() | Send a message object (EmailMessage). |
SMTP.sendmail() | Send mail with specified addresses and message. |
SMTP.starttls() | Put the SMTP connection in TLS mode. |
SMTP_SSL | SMTP client with implicit TLS connection. |
SMTPException | Base exception class for SMTP errors. |