Go to the latest version of this document.

# ``twisted`.`mail`.`smtp``

module documentation
(source)

Simple Mail Transfer Protocol implementation.

Class | `Address` | Parse and hold an RFC 2821 address.
Class | `ESMTP` | No class docstring; 0/10 instance variable, 0/1 class variable, 4/12 methods documented
Class | `ESMTPClient` | A client for sending emails over ESMTP.
Class | `ESMTPSender` | Undocumented
Class | `ESMTPSenderFactory` | Utility factory for sending emails easily.
Class | `LOGINCredentials` | `LOGINCredentials` generates challenges for LOGIN authentication.
Class | `PLAINAuthenticator` | Undocumented
Class | `SenderMixin` | Utility class for sending emails easily.
Class | `SMTP` | SMTP server-side protocol.
Class | `SMTPClient` | SMTP client for sending emails.
Class | `SMTPFactory` | Factory for SMTP.
Class | `SMTPSender` | SMTP protocol that sends a single email based on information it gets from its factory, a `SMTPSenderFactory`.
Class | `SMTPSenderFactory` | Utility factory for sending emails easily.
Class | `User` | Hold information about and SMTP message recipient, including information on where the message came from
Class | `xtextStreamReader` | Undocumented
Class | `xtextStreamWriter` | Undocumented
Exception | `AddressError` | Parse error in address
Exception | `AUTHDeclinedError` | The server rejected our credentials.
Exception | `AuthenticationError` | An error occurred while authenticating.
Exception | `AUTHRequiredError` | Authentication was required but the server does not support it.
Exception | `EHLORequiredError` | The server does not support EHLO.
Exception | `ESMTPClientError` | Base class for ESMTP client errors.
Exception | `SMTPAddressError` | Undocumented
Exception | `SMTPBadRcpt` | Undocumented
Exception | `SMTPBadSender` | Undocumented
Exception | `SMTPClientError` | Base class for SMTP client errors.
Exception | `SMTPConnectError` | Failed to connect to the mail exchange host.
Exception | `SMTPDeliveryError` | Indicates that a delivery attempt has had an error.
Exception | `SMTPError` | Undocumented
Exception | `SMTPProtocolError` | The server sent a mangled response.
Exception | `SMTPServerError` | Undocumented
Exception | `SMTPTimeoutError` | Failed to receive a response from the server in the expected time period.
Exception | `TLSError` | An error occurred while negiotiating for transport security.
Exception | `TLSRequiredError` | Transport security was required but the server does not support it.
Function | `idGenerator` | Undocumented
Function | `messageid` | Return a globally unique random string in RFC 2822 Message-ID format
Function | `quoteaddr` | Turn an email address, possibly with realname part etc, into a form suitable for and SMTP envelope.
Function | `rfc822date` | Format an RFC-2822 compliant date string.
Function | `sendmail` | Send an email.
Function | `xtext_codec` | Undocumented
Function | `xtext_decode` | Decode the xtext-encoded string `s`.
Function | `xtext_encode` | Undocumented
Constant | `SUCCESS` | Undocumented
Variable | `atom` | Undocumented
Variable | `AUTH` | Undocumented
Variable | `COMMAND` | Undocumented
Variable | `DATA` | Undocumented
Variable | `DNSNAME` | Undocumented
Variable | `_gen` | Undocumented

def idGenerator(): (source)

Undocumented

def messageid(uniq=None, N=lambda: next(_gen)): (source)

Return a globally unique random string in RFC 2822 Message-ID format

<datetime.pid.random@host.dom.ain>

Optional uniq string will be added to strengthen uniqueness if given.

def quoteaddr(addr): (source)

Turn an email address, possibly with realname part etc, into a form suitable for and SMTP envelope.

def rfc822date(timeinfo=None, local=1): (source)

Format an RFC-2822 compliant date string.

Parameters
timeinfo | (optional) A sequence as returned by `time.localtime()` or `time.gmtime()`. Default is now.
local | (optional) Indicates if the supplied time is local or universal time, or if no time is given, whether now should be local or universal time. Default is local, as suggested (SHOULD) by rfc-2822.

Returns
A `bytes` representing the time and date in RFC-2822 format.

def sendmail(smtphost, from_addr, to_addrs, msg, senderDomainName=None, port=25, reactor=reactor, username=None, password=None, requireAuthentication=False, requireTransportSecurity=False): (source)

Send an email.

This interface is intended to be a replacement for `smtplib.SMTP.sendmail` and related methods. To maintain backwards compatibility, it will fall back to plain SMTP, if ESMTP support is not available. If ESMTP support is available, it will attempt to provide encryption via STARTTLS and authentication if a secret is provided.

Parameters
smtphost:`bytes` | The host the message should be sent to.
from_addr:`bytes` | The (envelope) address sending this mail.
to_addrs:`list` of `bytes` or `bytes` | A list of addresses to send this mail to. A string will be treated as a list of one address.

msg

The message, including headers, either as a file or a string. File-like objects need to support read() and close(). Lines must be delimited by '\n'. If you pass something that doesn't look like a file, we try to convert it to a string (so you should be able to pass an `email.message` directly, but doing the conversion with `email.generator` manually will give you more control over the process).

senderDomainName:`bytes` | Name by which to identify. If None, try to pick something sane (but this depends on external configuration and may not succeed).
port:`int` | Remote port to which to connect.
reactor | The `reactor` used to make the TCP connection.
username:`bytes` or `unicode` | The username to use, if wanting to authenticate.
password:`bytes` or `unicode` | The secret to use, if wanting to authenticate. If you do not specify this, SMTP authentication will not occur.
requireAuthentication:`bool` | Whether or not authentication is required.
requireTransportSecurity:`bool` | Whether or not STARTTLS is required.

Returns

`Deferred`

A cancellable `Deferred`, its callback will be called if a message is sent to ANY address, the errback if no message is sent. When the `cancel` method is called, it will stop retrying and disconnect the connection immediately.

The callback will be called with a tuple (numOk, addresses) where numOk is the number of successful recipient addresses and addresses is a list of tuples (address, code, resp) giving the response to the RCPT command for each address.

def xtext_codec(name): (source)

Undocumented

def xtext_decode(s, errors=None): (source)

Decode the xtext-encoded string `s`.

Parameters
s | String to decode.
errors | codec error handling scheme.

Returns
The decoded string.

def xtext_encode(s, errors=None): (source)

Undocumented

SUCCESS = (source)

Undocumented

Value

    dict.fromkeys(range(200, 300))

atom: `bytes` = (source)

Undocumented

AUTH = (source)

Undocumented

COMMAND = (source)

Undocumented

DATA = (source)

Undocumented

DNSNAME = (source)

Undocumented

_gen = (source)

Undocumented