1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.tlslite.integration.SMTP_TLS</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.<a href="gdata.tlslite.html"><font color="#ffffff">tlslite</font></a>.<a href="gdata.tlslite.integration.html"><font color="#ffffff">integration</font></a>.SMTP_TLS</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/afshar/wrk/gdata-python-client/src/gdata/tlslite/integration/SMTP_TLS.py">/home/afshar/wrk/gdata-python-client/src/gdata/tlslite/integration/SMTP_TLS.py</a></font></td></tr></table>
<p><tt>TLS Lite + smtplib.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="smtplib.html#SMTP">smtplib.SMTP</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.tlslite.integration.SMTP_TLS.html#SMTP_TLS">SMTP_TLS</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="SMTP_TLS">class <strong>SMTP_TLS</strong></a>(<a href="smtplib.html#SMTP">smtplib.SMTP</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>This class extends L{smtplib.<a href="smtplib.html#SMTP">SMTP</a>} with TLS support.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="SMTP_TLS-starttls"><strong>starttls</strong></a>(self, username<font color="#909090">=None</font>, password<font color="#909090">=None</font>, sharedKey<font color="#909090">=None</font>, certChain<font color="#909090">=None</font>, privateKey<font color="#909090">=None</font>, cryptoID<font color="#909090">=None</font>, protocol<font color="#909090">=None</font>, x509Fingerprint<font color="#909090">=None</font>, x509TrustList<font color="#909090">=None</font>, x509CommonName<font color="#909090">=None</font>, settings<font color="#909090">=None</font>)</dt><dd><tt>Puts the connection to the <a href="smtplib.html#SMTP">SMTP</a> server into TLS mode.<br>
<br>
If the server supports TLS, this will encrypt the rest of the <a href="smtplib.html#SMTP">SMTP</a><br>
session.<br>
<br>
For client authentication, use one of these argument<br>
combinations:<br>
- username, password (SRP)<br>
- username, sharedKey (shared-key)<br>
- certChain, privateKey (certificate)<br>
<br>
For server authentication, you can either rely on the<br>
implicit mutual authentication performed by SRP or<br>
shared-keys, or you can do certificate-based server<br>
authentication with one of these argument combinations:<br>
- cryptoID[, protocol] (requires cryptoIDlib)<br>
- x509Fingerprint<br>
- x509TrustList[, x509CommonName] (requires cryptlib_py)<br>
<br>
Certificate-based server authentication is compatible with<br>
SRP or certificate-based client authentication. It is<br>
not compatible with shared-keys.<br>
<br>
The caller should be prepared to handle TLS-specific<br>
exceptions. See the client handshake functions in<br>
L{tlslite.TLSConnection.TLSConnection} for details on which<br>
exceptions might be raised.<br>
<br>
@type username: str<br>
@param username: SRP or shared-key username. Requires the<br>
'password' or 'sharedKey' argument.<br>
<br>
@type password: str<br>
@param password: SRP password for mutual authentication.<br>
Requires the 'username' argument.<br>
<br>
@type sharedKey: str<br>
@param sharedKey: Shared key for mutual authentication.<br>
Requires the 'username' argument.<br>
<br>
@type certChain: L{tlslite.X509CertChain.X509CertChain} or<br>
L{cryptoIDlib.CertChain.CertChain}<br>
@param certChain: Certificate chain for client authentication.<br>
Requires the 'privateKey' argument. Excludes the SRP or<br>
shared-key related arguments.<br>
<br>
@type privateKey: L{tlslite.utils.RSAKey.RSAKey}<br>
@param privateKey: Private key for client authentication.<br>
Requires the 'certChain' argument. Excludes the SRP or<br>
shared-key related arguments.<br>
<br>
@type cryptoID: str<br>
@param cryptoID: cryptoID for server authentication. Mutually<br>
exclusive with the 'x509...' arguments.<br>
<br>
@type protocol: str<br>
@param protocol: cryptoID protocol URI for server<br>
authentication. Requires the 'cryptoID' argument.<br>
<br>
@type x509Fingerprint: str<br>
@param x509Fingerprint: Hex-encoded X.509 fingerprint for<br>
server authentication. Mutually exclusive with the 'cryptoID'<br>
and 'x509TrustList' arguments.<br>
<br>
@type x509TrustList: list of L{tlslite.X509.X509}<br>
@param x509TrustList: A list of trusted root certificates. The<br>
other party must present a certificate chain which extends to<br>
one of these root certificates. The cryptlib_py module must be<br>
installed to use this parameter. Mutually exclusive with the<br>
'cryptoID' and 'x509Fingerprint' arguments.<br>
<br>
@type x509CommonName: str<br>
@param x509CommonName: The end-entity certificate's 'CN' field<br>
must match this value. For a web server, this is typically a<br>
server name such as 'www.amazon.com'. Mutually exclusive with<br>
the 'cryptoID' and 'x509Fingerprint' arguments. Requires the<br>
'x509TrustList' argument.<br>
<br>
@type settings: L{tlslite.HandshakeSettings.HandshakeSettings}<br>
@param settings: Various settings which can be used to control<br>
the ciphersuites, certificate types, and SSL/TLS versions<br>
offered by the client.</tt></dd></dl>
<hr>
Methods inherited from <a href="smtplib.html#SMTP">smtplib.SMTP</a>:<br>
<dl><dt><a name="SMTP_TLS-__init__"><strong>__init__</strong></a>(self, host<font color="#909090">=''</font>, port<font color="#909090">=0</font>, local_hostname<font color="#909090">=None</font>, timeout<font color="#909090">=<object object></font>)</dt><dd><tt>Initialize a new instance.<br>
<br>
If specified, `host' is the name of the remote host to which to<br>
connect. If specified, `port' specifies the port to which to connect.<br>
By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised<br>
if the specified `host' doesn't respond correctly. If specified,<br>
`local_hostname` is used as the FQDN of the local host. By default,<br>
the local hostname is found using socket.getfqdn().</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-close"><strong>close</strong></a>(self)</dt><dd><tt>Close the connection to the <a href="smtplib.html#SMTP">SMTP</a> server.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-connect"><strong>connect</strong></a>(self, host<font color="#909090">='localhost'</font>, port<font color="#909090">=0</font>)</dt><dd><tt>Connect to a host on a given port.<br>
<br>
If the hostname ends with a colon (`:') followed by a number, and<br>
there is no port specified, that suffix will be stripped off and the<br>
number interpreted as the port number to use.<br>
<br>
Note: This method is automatically invoked by __init__, if a host is<br>
specified during instantiation.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-data"><strong>data</strong></a>(self, msg)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'DATA' command -- sends message data to server.<br>
<br>
Automatically quotes lines beginning with a period per rfc821.<br>
Raises SMTPDataError if there is an unexpected reply to the<br>
DATA command; the return value from this method is the final<br>
response code received when the all data is sent.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-docmd"><strong>docmd</strong></a>(self, cmd, args<font color="#909090">=''</font>)</dt><dd><tt>Send a command, and return its response code.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-ehlo"><strong>ehlo</strong></a>(self, name<font color="#909090">=''</font>)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'ehlo' command.<br>
Hostname to send for this command defaults to the FQDN of the local<br>
host.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-ehlo_or_helo_if_needed"><strong>ehlo_or_helo_if_needed</strong></a>(self)</dt><dd><tt>Call <a href="#SMTP_TLS-ehlo_msg">ehlo</a>() and/or <a href="#SMTP_TLS-helo">helo</a>() if needed.<br>
<br>
If there has been no previous EHLO or HELO command this session, this<br>
method tries ESMTP EHLO first.<br>
<br>
This method may raise the following exceptions:<br>
<br>
SMTPHeloError The server didn't reply properly to<br>
the helo greeting.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-expn"><strong>expn</strong></a>(self, address)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'expn' command -- expands a mailing list.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-getreply"><strong>getreply</strong></a>(self)</dt><dd><tt>Get a reply from the server.<br>
<br>
Returns a tuple consisting of:<br>
<br>
- server response code (e.g. '250', or such, if all goes well)<br>
Note: returns -1 if it can't read response code.<br>
<br>
- server response string corresponding to response code (multiline<br>
responses are converted to a single, multiline string).<br>
<br>
Raises SMTPServerDisconnected if end-of-file is reached.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-has_extn"><strong>has_extn</strong></a>(self, opt)</dt><dd><tt>Does the server support a given <a href="smtplib.html#SMTP">SMTP</a> service extension?</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-helo"><strong>helo</strong></a>(self, name<font color="#909090">=''</font>)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'helo' command.<br>
Hostname to send for this command defaults to the FQDN of the local<br>
host.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-help"><strong>help</strong></a>(self, args<font color="#909090">=''</font>)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'help' command.<br>
Returns help text from server.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-login"><strong>login</strong></a>(self, user, password)</dt><dd><tt>Log in on an <a href="smtplib.html#SMTP">SMTP</a> server that requires authentication.<br>
<br>
The arguments are:<br>
- user: The user name to authenticate with.<br>
- password: The password for the authentication.<br>
<br>
If there has been no previous EHLO or HELO command this session, this<br>
method tries ESMTP EHLO first.<br>
<br>
This method will return normally if the authentication was successful.<br>
<br>
This method may raise the following exceptions:<br>
<br>
SMTPHeloError The server didn't reply properly to<br>
the helo greeting.<br>
SMTPAuthenticationError The server didn't accept the username/<br>
password combination.<br>
SMTPException No suitable authentication method was<br>
found.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-mail"><strong>mail</strong></a>(self, sender, options<font color="#909090">=[]</font>)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'mail' command -- begins mail xfer session.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-noop"><strong>noop</strong></a>(self)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'noop' command -- doesn't do anything :></tt></dd></dl>
<dl><dt><a name="SMTP_TLS-putcmd"><strong>putcmd</strong></a>(self, cmd, args<font color="#909090">=''</font>)</dt><dd><tt>Send a command to the server.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-quit"><strong>quit</strong></a>(self)</dt><dd><tt>Terminate the <a href="smtplib.html#SMTP">SMTP</a> session.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-rcpt"><strong>rcpt</strong></a>(self, recip, options<font color="#909090">=[]</font>)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'rcpt' command -- indicates 1 recipient for this mail.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-rset"><strong>rset</strong></a>(self)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'rset' command -- resets session.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-send"><strong>send</strong></a>(self, str)</dt><dd><tt>Send `str' to the server.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-sendmail"><strong>sendmail</strong></a>(self, from_addr, to_addrs, msg, mail_options<font color="#909090">=[]</font>, rcpt_options<font color="#909090">=[]</font>)</dt><dd><tt>This command performs an entire mail transaction.<br>
<br>
The arguments are:<br>
- from_addr : The address sending this mail.<br>
- to_addrs : A list of addresses to send this mail to. A bare<br>
string will be treated as a list with 1 address.<br>
- msg : The message to send.<br>
- mail_options : List of ESMTP options (such as 8bitmime) for the<br>
mail command.<br>
- rcpt_options : List of ESMTP options (such as DSN commands) for<br>
all the rcpt commands.<br>
<br>
If there has been no previous EHLO or HELO command this session, this<br>
method tries ESMTP EHLO first. If the server does ESMTP, message size<br>
and each of the specified options will be passed to it. If EHLO<br>
fails, HELO will be tried and ESMTP options suppressed.<br>
<br>
This method will return normally if the mail is accepted for at least<br>
one recipient. It returns a dictionary, with one entry for each<br>
recipient that was refused. Each entry contains a tuple of the <a href="smtplib.html#SMTP">SMTP</a><br>
error code and the accompanying error message sent by the server.<br>
<br>
This method may raise the following exceptions:<br>
<br>
SMTPHeloError The server didn't reply properly to<br>
the helo greeting.<br>
SMTPRecipientsRefused The server rejected ALL recipients<br>
(no mail was sent).<br>
SMTPSenderRefused The server didn't accept the from_addr.<br>
SMTPDataError The server replied with an unexpected<br>
error code (other than a refusal of<br>
a recipient).<br>
<br>
Note: the connection will be open even after an exception is raised.<br>
<br>
Example:<br>
<br>
>>> import smtplib<br>
>>> s=smtplib.<a href="smtplib.html#SMTP">SMTP</a>("localhost")<br>
>>> tolist=["one@one.org","two@two.org","three@three.org","four@four.org"]<br>
>>> msg = '''\<br>
... From: Me@my.org<br>
... Subject: testin'...<br>
...<br>
... This is a test '''<br>
>>> s.<a href="#SMTP_TLS-sendmail">sendmail</a>("me@my.org",tolist,msg)<br>
{ "three@three.org" : ( 550 ,"User unknown" ) }<br>
>>> s.<a href="#SMTP_TLS-quit">quit</a>()<br>
<br>
In the above example, the message was accepted for delivery to three<br>
of the four addresses, and one was rejected, with the error code<br>
550. If all addresses are accepted, then the method will return an<br>
empty dictionary.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-set_debuglevel"><strong>set_debuglevel</strong></a>(self, debuglevel)</dt><dd><tt>Set the debug output level.<br>
<br>
A non-false value results in debug messages for connection and for all<br>
messages sent to and received from the server.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-verify"><strong>verify</strong></a>(self, address)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'verify' command -- checks for address validity.</tt></dd></dl>
<dl><dt><a name="SMTP_TLS-vrfy"><strong>vrfy</strong></a> = verify(self, address)</dt><dd><tt><a href="smtplib.html#SMTP">SMTP</a> 'verify' command -- checks for address validity.</tt></dd></dl>
<hr>
Data and other attributes inherited from <a href="smtplib.html#SMTP">smtplib.SMTP</a>:<br>
<dl><dt><strong>debuglevel</strong> = 0</dl>
<dl><dt><strong>does_esmtp</strong> = 0</dl>
<dl><dt><strong>ehlo_msg</strong> = 'ehlo'</dl>
<dl><dt><strong>ehlo_resp</strong> = None</dl>
<dl><dt><strong>file</strong> = None</dl>
<dl><dt><strong>helo_resp</strong> = None</dl>
</td></tr></table></td></tr></table>
</body></html>
|