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