Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex


18.13.1 SMTP Objects

AnSMTP instance has the following methods:

set_debuglevel(level)
Set the debug output level. A true value forlevel results indebug messages for connection and for all messages sent to andreceived from the server.

connect([host[, port]])
Connect to a host on a given port. The defaults are to connect to thelocal host at the standard SMTP port (25).If the hostname ends with a colon (":") followed by anumber, that suffix will be stripped off and the number interpreted asthe port number to use.This method is automatically invoked by the constructor if ahost is specified during instantiation.

docmd(cmd,[, argstring])
Send a commandcmd to the server. The optional argumentargstring is simply concatenated to the command, separated by aspace.

This returns a 2-tuple composed of a numeric response code and theactual response line (multiline responses are joined into one longline.)

In normal operation it should not be necessary to call this methodexplicitly. It is used to implement other methods and may be usefulfor testing private extensions.

If the connection to the server is lost while waiting for the reply,SMTPServerDisconnected will be raised.

helo([hostname])
Identify yourself to the SMTP server using "HELO". The hostnameargument defaults to the fully qualified domain name of the localhost.

In normal operation it should not be necessary to call this methodexplicitly. It will be implicitly called by thesendmail()when necessary.

ehlo([hostname])
Identify yourself to an ESMTP server using "EHLO". The hostnameargument defaults to the fully qualified domain name of the localhost. Examine the response for ESMTP option and store them for use byhas_extn().

Unless you wish to usehas_extn() before sendingmail, it should not be necessary to call this method explicitly. Itwill be implicitly called bysendmail() when necessary.

has_extn(name)
ReturnTrue ifname is in the set of SMTP serviceextensions returned by the server,False otherwise.Case is ignored.

verify(address)
Check the validity of an address on this server using SMTP "VRFY".Returns a tuple consisting of code 250 and a fullRFC 822 address(including human name) if the user address is valid. Otherwise returnsan SMTP error code of 400 or greater and an error string.

Note:Many sites disable SMTP "VRFY" in order to foil spammers.

login(user, password)
Log in on an SMTP server that requires authentication.The arguments are the username and the password to authenticate with.If there has been no previous "EHLO" or "HELO" command thissession, this method tries ESMTP "EHLO" first.This method will return normally if the authentication was successful,or may raise the following exceptions:

SMTPHeloError
The server didn't reply properly to the "HELO" greeting.
SMTPAuthenticationError
The server didn't accept the username/password combination.
SMTPException
No suitable authentication method was found.

starttls([keyfile[, certfile]])
Put the SMTP connection in TLS (Transport Layer Security) mode. AllSMTP commands that follow will be encrypted. You should then callehlo() again.

Ifkeyfile andcertfile are provided, these are passed tothesocket module'sssl() function.

sendmail(from_addr, to_addrs, msg[, mail_options, rcpt_options])
Send mail. The required arguments are anRFC 822 from-addressstring, a list ofRFC 822 to-address strings (a bare string will betreated as a list with 1 address), and a message string. The callermay pass a list of ESMTP options (such as "8bitmime") to be usedin "MAIL FROM" commands asmail_options. ESMTP options(such as "DSN" commands) that should be used with all "RCPT"commands can be passed asrcpt_options. (If you need to usedifferent ESMTP options to different recipients you have to use thelow-level methods such asmail,rcpt anddata to send the message.)

Note:Thefrom_addr andto_addrs parameters areused to construct the message envelope used by the transport agents.TheSMTP does not modify the message headers in any way.

If there has been no previous "EHLO" or "HELO" command thissession, this method tries ESMTP "EHLO" first. If the server doesESMTP, message size and each of the specified options will be passedto it (if the option is in the feature set the server advertises). If"EHLO" fails, "HELO" will be tried and ESMTP optionssuppressed.

This method will return normally if the mail is accepted for at leastone recipient. Otherwise it will throw an exception. That is, if thismethod does not throw an exception, then someone should get your mail.If this method does not throw an exception, it returns a dictionary,with one entry for each recipient that was refused. Each entrycontains a tuple of the SMTP error code and the accompanying errormessage sent by the server.

This method may raise the following exceptions:

SMTPRecipientsRefused
All recipients were refused. Nobody got the mail. Therecipients attribute of the exception object is a dictionarywith information about the refused recipients (like the one returnedwhen at least one recipient was accepted).

SMTPHeloError
The server didn't reply properly to the "HELO" greeting.

SMTPSenderRefused
The server didn't accept thefrom_addr.

SMTPDataError
The server replied with an unexpected error code (other than a refusalof a recipient).

Unless otherwise noted, the connection will be open even afteran exception is raised.

quit()
Terminate the SMTP session and close the connection.

Low-level methods corresponding to the standard SMTP/ESMTP commands"HELP", "RSET", "NOOP", "MAIL", "RCPT", and"DATA" are also supported. Normally these do not need to becalled directly, so they are not documented here. For details,consult the module code.


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp