smtplib.SMTP¶
-
class
smtplib.SMTP(host='', port=0, local_hostname=None, timeout=<object object>)[source]¶ This class manages a connection to an SMTP or ESMTP server. SMTP Objects:
- SMTP objects have the following attributes:
- helo_resp
- This is the message given by the server in response to the most recent HELO command.
- ehlo_resp
- This is the message given by the server in response to the most recent EHLO command. This is usually multiline.
- does_esmtp
- This is a True value _after you do an EHLO command_, if the server supports ESMTP.
- esmtp_features
This is a dictionary, which, if the server supports ESMTP, will _after you do an EHLO command_, contain the names of the SMTP service extensions this server supports, and their parameters (if any).
Note, all extension names are mapped to lower case in the dictionary.
See each method’s docstrings for details. In general, there is a method of the same name to perform each SMTP command. There is also a method called ‘sendmail’ that will do an entire mail transaction.
Methods¶
__init__([host, port, local_hostname, timeout]) |
Initialize a new instance. |
_get_socket(host, port, timeout) |
|
close() |
Close the connection to the SMTP server. |
connect([host, port]) |
Connect to a host on a given port. |
data(msg) |
SMTP ‘DATA’ command – sends message data to server. |
docmd(cmd[, args]) |
Send a command, and return its response code. |
ehlo([name]) |
SMTP ‘ehlo’ command. |
ehlo_or_helo_if_needed() |
Call self.ehlo() and/or self.helo() if needed. |
expn(address) |
SMTP ‘expn’ command – expands a mailing list. |
getreply() |
Get a reply from the server. |
has_extn(opt) |
Does the server support a given SMTP service extension? |
helo([name]) |
SMTP ‘helo’ command. |
help([args]) |
SMTP ‘help’ command. |
login(user, password) |
Log in on an SMTP server that requires authentication. |
mail(sender[, options]) |
SMTP ‘mail’ command – begins mail xfer session. |
noop() |
SMTP ‘noop’ command – doesn’t do anything :> |
putcmd(cmd[, args]) |
Send a command to the server. |
quit() |
Terminate the SMTP session. |
rcpt(recip[, options]) |
SMTP ‘rcpt’ command – indicates 1 recipient for this mail. |
rset() |
SMTP ‘rset’ command – resets session. |
send(str) |
Send `str’ to the server. |
sendmail(from_addr, to_addrs, msg[, ...]) |
This command performs an entire mail transaction. |
set_debuglevel(debuglevel) |
Set the debug output level. |
starttls([keyfile, certfile]) |
Puts the connection to the SMTP server into TLS mode. |
verify(address) |
SMTP ‘verify’ command – checks for address validity. |
vrfy(address) |
SMTP ‘verify’ command – checks for address validity. |
Attributes¶
debuglevel |
|
default_port |
|
does_esmtp |
|
ehlo_msg |
|
ehlo_resp |
|
file |
|
helo_resp |