On this page
smtplib.SMTP
Prev: smtplib.quotedata | Up: smtplib | Next: smtplib.SMTP_SSL
Rel: smtplib.quoteaddr, smtplib.quotedata, smtplib.SMTP_SSL, smtplib.SMTPAuthenticationError
Ref: docs.python.org — smtplib.SMTP
Tags: #public #python3 #stdlib #smtplib
Import
import smtplib
from smtplib import SMTP
Signature & Overview
smtplib.SMTP(host='', port=0, local_hostname=None, timeout=<object object at 0x1040b4980>, source_address=None)
This class manages a connection to an SMTP or ESMTP server.
Methods & Attributes
SMTP.auth(self, mechanism, authobject, *, initial_response_ok=True)— Authentication command - requires response processing.SMTP.auth_cram_md5(self, challenge=None)— Authobject to use with CRAM-MD5 authentication. Requires self.user and self.password to be set.SMTP.auth_login(self, challenge=None)— Authobject to use with LOGIN authentication. Requires self.user and self.password to be set.SMTP.auth_plain(self, challenge=None)— Authobject to use with PLAIN authentication. Requires self.user and self.password to be set.SMTP.close(self)— Close the connection to the SMTP server.SMTP.connect(self, host='localhost', port=0, source_address=None)— Connect to a host on a given port.SMTP.data(self, msg)— SMTP 'DATA' command -- sends message data to server.SMTP.docmd(self, cmd, args='')— Send a command, and return its response code.SMTP.ehlo(self, name='')— SMTP 'ehlo' command.SMTP.ehlo_or_helo_if_needed(self)— Call self.ehlo() and/or self.helo() if needed.SMTP.expn(self, address)— SMTP 'expn' command -- expands a mailing list.SMTP.getreply(self)— Get a reply from the server.SMTP.has_extn(self, opt)— Does the server support a given SMTP service extension?SMTP.helo(self, name='')— SMTP 'helo' command.SMTP.help(self, args='')— SMTP 'help' command.SMTP.login(self, user, password, *, initial_response_ok=True)— Log in on an SMTP server that requires authentication.SMTP.mail(self, sender, options=())— SMTP 'mail' command -- begins mail xfer session.SMTP.noop(self)— SMTP 'noop' command -- doesn't do anything :>SMTP.putcmd(self, cmd, args='')— Send a command to the server.SMTP.quit(self)— Terminate the SMTP session.SMTP.rcpt(self, recip, options=())— SMTP 'rcpt' command -- indicates 1 recipient for this mail.SMTP.rset(self)— SMTP 'rset' command -- resets session.SMTP.send(self, s)— Send 's' to the server.SMTP.send_message(self, msg, from_addr=None, to_addrs=None, mail_options=(), rcpt_options=())— Converts message to a bytestring and passes it to sendmail.SMTP.sendmail(self, from_addr, to_addrs, msg, mail_options=(), rcpt_options=())— This command performs an entire mail transaction.SMTP.set_debuglevel(self, debuglevel)— Set the debug output level.SMTP.starttls(self, *, context=None)— Puts the connection to the SMTP server into TLS mode.SMTP.verify(self, address)— SMTP 'verify' command -- checks for address validity.SMTP.vrfy(self, address)— SMTP 'verify' command -- checks for address validity.
Usage
import smtplib
# Plain/STARTTLS SMTP client (call starttls(context=ssl.create_default_context()) before login)
assert hasattr(smtplib, 'SMTP')
Gotchas
- Always call
starttls()(port 587) or useSMTP_SSL(port 465) and passtimeout=30.
REPL Inspect
from smtplib import SMTP
help(SMTP)
Linked from
- tuts/python3/stdlib_module/smtplib
- tuts/python3/stdlib_module/smtplib/quoteaddr
- tuts/python3/stdlib_module/smtplib/quotedata
- tuts/python3/stdlib_module/smtplib/SMTP_SSL
- tuts/python3/stdlib_module/smtplib/SMTPAuthenticationError
- tuts/python3/stdlib_module/smtplib/SMTPConnectError
- tuts/python3/stdlib_module/smtplib/SMTPDataError
- tuts/python3/stdlib_module/smtplib/SMTPException
- tuts/python3/stdlib_module/smtplib/SMTPHeloError
- tuts/python3/stdlib_module/smtplib/SMTPNotSupportedError
- tuts/python3/stdlib_module/smtplib/SMTPRecipientsRefused
- tuts/python3/stdlib_module/smtplib/SMTPResponseException
- tuts/python3/stdlib_module/smtplib/SMTPSenderRefused
- tuts/python3/stdlib_module/smtplib/SMTPServerDisconnected
Related notes
- tuts/python3/stdlib_module/smtplib/quoteaddr Linked here; links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/quotedata Linked here; links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTP_SSL Linked here; links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPAuthenticationError Linked here; links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPConnectError links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPDataError links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPException links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPHeloError links to this page; shared tags: #smtplib, #stdlib
- tuts/python3/stdlib_module/smtplib/SMTPNotSupportedError links to this page; shared tags: #smtplib, #stdlib