Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2623)

Delta Between Two Patch Sets: Lib/smtplib.py

Issue 11281: smtplib: add ability to bind to specific source IP address/port
Left Patch Set: Created 2 years, 2 months ago
Right Patch Set: Created 2 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/smtplib.rst ('k') | Lib/test/mock_socket.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 '''SMTP/ESMTP client class. 3 '''SMTP/ESMTP client class.
4 4
5 This should follow RFC 821 (SMTP), RFC 1869 (ESMTP), RFC 2554 (SMTP 5 This should follow RFC 821 (SMTP), RFC 1869 (ESMTP), RFC 2554 (SMTP
6 Authentication) and RFC 2487 (Secure SMTP over TLS). 6 Authentication) and RFC 2487 (Secure SMTP over TLS).
7 7
8 Notes: 8 Notes:
9 9
10 Please remember, when doing ESMTP, that the names of the SMTP service 10 Please remember, when doing ESMTP, that the names of the SMTP service
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 """ 227 """
228 debuglevel = 0 228 debuglevel = 0
229 file = None 229 file = None
230 helo_resp = None 230 helo_resp = None
231 ehlo_msg = "ehlo" 231 ehlo_msg = "ehlo"
232 ehlo_resp = None 232 ehlo_resp = None
233 does_esmtp = 0 233 does_esmtp = 0
234 234
235 def __init__(self, host='', port=0, local_hostname=None, 235 def __init__(self, host='', port=0, local_hostname=None,
236 timeout=socket._GLOBAL_DEFAULT_TIMEOUT, 236 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
237 source_address=('', 0)): 237 source_address=None):
238 """Initialize a new instance. 238 """Initialize a new instance.
239 239
240 If specified, `host' is the name of the remote host to which to 240 If specified, `host' is the name of the remote host to which to
241 connect. If specified, `port' specifies the port to which to connect. 241 connect. If specified, `port' specifies the port to which to connect.
242 By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised 242 By default, smtplib.SMTP_PORT is used. An SMTPConnectError is raised
243 if the specified `host' doesn't respond correctly. If specified, 243 if the specified `host' doesn't respond correctly. If specified,
244 `local_hostname` is used as the FQDN of the local host. By default, 244 `local_hostname` is used as the FQDN of the local host. By default,
245 the local hostname is found using socket.getfqdn(). The `source_address' 245 the local hostname is found using socket.getfqdn(). The `source_address'
246 parameter takes a 2-tuple (host, port) like socket.create_connection, 246 parameter takes a 2-tuple (host, port) like socket.create_connection,
247 for the socket to bind to as its source address before connecting. 247 for the socket to bind to as its source address before connecting.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 A non-false value results in debug messages for connection and for all 281 A non-false value results in debug messages for connection and for all
282 messages sent to and received from the server. 282 messages sent to and received from the server.
283 283
284 """ 284 """
285 self.debuglevel = debuglevel 285 self.debuglevel = debuglevel
286 286
287 def _get_socket(self, host, port, timeout): 287 def _get_socket(self, host, port, timeout):
288 # This makes it simpler for SMTP_SSL to use the SMTP connect code 288 # This makes it simpler for SMTP_SSL to use the SMTP connect code
289 # and just alter the socket connection bit. 289 # and just alter the socket connection bit.
290 if self.debuglevel > 0: 290 if self.debuglevel > 0:
291 print('connect: to', (host, port)+self.source_address, file=stderr) 291 print('connect: to', (host, port), self.source_address, file=stderr)
292 return socket.create_connection((host, port), timeout, 292 return socket.create_connection((host, port), timeout,
293 self.source_address) 293 self.source_address)
294 294
295 def connect(self, host='localhost', port=0, source_address=None): 295 def connect(self, host='localhost', port=0, source_address=None):
296 """Connect to a host on a given port. 296 """Connect to a host on a given port.
297 297
298 If the hostname ends with a colon (`:') followed by a number, and 298 If the hostname ends with a colon (`:') followed by a number, and
299 there is no port specified, that suffix will be stripped off and the 299 there is no port specified, that suffix will be stripped off and the
300 number interpreted as the port number to use. 300 number interpreted as the port number to use.
301 301
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 line = sys.stdin.readline() 896 line = sys.stdin.readline()
897 if not line: 897 if not line:
898 break 898 break
899 msg = msg + line 899 msg = msg + line
900 print("Message length is %d" % len(msg)) 900 print("Message length is %d" % len(msg))
901 901
902 server = SMTP('localhost') 902 server = SMTP('localhost')
903 server.set_debuglevel(1) 903 server.set_debuglevel(1)
904 server.sendmail(fromaddr, toaddrs, msg) 904 server.sendmail(fromaddr, toaddrs, msg)
905 server.quit() 905 server.quit()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7