SMTP 'ehlo' command. Hostname to send for this command defaults to the FQDN of the local host.
(self, name='')
| 450 | return (code, msg) |
| 451 | |
| 452 | def ehlo(self, name=''): |
| 453 | """ SMTP 'ehlo' command. |
| 454 | Hostname to send for this command defaults to the FQDN of the local |
| 455 | host. |
| 456 | """ |
| 457 | self.esmtp_features = {} |
| 458 | self.putcmd(self.ehlo_msg, name or self.local_hostname) |
| 459 | (code, msg) = self.getreply() |
| 460 | # According to RFC1869 some (badly written) |
| 461 | # MTA's will disconnect on an ehlo. Toss an exception if |
| 462 | # that happens -ddm |
| 463 | if code == -1 and len(msg) == 0: |
| 464 | self.close() |
| 465 | raise SMTPServerDisconnected("Server not connected") |
| 466 | self.ehlo_resp = msg |
| 467 | if code != 250: |
| 468 | return (code, msg) |
| 469 | self.does_esmtp = True |
| 470 | #parse the ehlo response -ddm |
| 471 | assert isinstance(self.ehlo_resp, bytes), repr(self.ehlo_resp) |
| 472 | resp = self.ehlo_resp.decode("latin-1").split('\n') |
| 473 | del resp[0] |
| 474 | for each in resp: |
| 475 | # To be able to communicate with as many SMTP servers as possible, |
| 476 | # we have to take the old-style auth advertisement into account, |
| 477 | # because: |
| 478 | # 1) Else our SMTP feature parser gets confused. |
| 479 | # 2) There are some servers that only advertise the auth methods we |
| 480 | # support using the old style. |
| 481 | auth_match = OLDSTYLE_AUTH.match(each) |
| 482 | if auth_match: |
| 483 | # This doesn't remove duplicates, but that's no problem |
| 484 | self.esmtp_features["auth"] = self.esmtp_features.get("auth", "") \ |
| 485 | + " " + auth_match.groups(0)[0] |
| 486 | continue |
| 487 | |
| 488 | # RFC 1869 requires a space between ehlo keyword and parameters. |
| 489 | # It's actually stricter, in that only spaces are allowed between |
| 490 | # parameters, but were not going to check for that here. Note |
| 491 | # that the space isn't present if there are no parameters. |
| 492 | m = re.match(r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*) ?', each) |
| 493 | if m: |
| 494 | feature = m.group("feature").lower() |
| 495 | params = m.string[m.end("feature"):].strip() |
| 496 | if feature == "auth": |
| 497 | self.esmtp_features[feature] = self.esmtp_features.get(feature, "") \ |
| 498 | + " " + params |
| 499 | else: |
| 500 | self.esmtp_features[feature] = params |
| 501 | return (code, msg) |
| 502 | |
| 503 | def has_extn(self, opt): |
| 504 | """Does the server support a given SMTP service extension?""" |