Log in on an SMTP server that requires authentication. The arguments are: - user: The user name to authenticate with. - password: The password for the authentication. Keyword arguments: - initial_response_ok: Allow sending the RFC 495
(self, user, password, *, initial_response_ok=True)
| 694 | return self.password |
| 695 | |
| 696 | def login(self, user, password, *, initial_response_ok=True): |
| 697 | """Log in on an SMTP server that requires authentication. |
| 698 | |
| 699 | The arguments are: |
| 700 | - user: The user name to authenticate with. |
| 701 | - password: The password for the authentication. |
| 702 | |
| 703 | Keyword arguments: |
| 704 | - initial_response_ok: Allow sending the RFC 4954 initial-response |
| 705 | to the AUTH command, if the authentication methods supports it. |
| 706 | |
| 707 | If there has been no previous EHLO or HELO command this session, this |
| 708 | method tries ESMTP EHLO first. |
| 709 | |
| 710 | This method will return normally if the authentication was successful. |
| 711 | |
| 712 | This method may raise the following exceptions: |
| 713 | |
| 714 | SMTPHeloError The server didn't reply properly to |
| 715 | the helo greeting. |
| 716 | SMTPAuthenticationError The server didn't accept the username/ |
| 717 | password combination. |
| 718 | SMTPNotSupportedError The AUTH command is not supported by the |
| 719 | server. |
| 720 | SMTPException No suitable authentication method was |
| 721 | found. |
| 722 | """ |
| 723 | |
| 724 | self.ehlo_or_helo_if_needed() |
| 725 | if not self.has_extn("auth"): |
| 726 | raise SMTPNotSupportedError( |
| 727 | "SMTP AUTH extension not supported by server.") |
| 728 | |
| 729 | # Authentication methods the server claims to support |
| 730 | advertised_authlist = self.esmtp_features["auth"].split() |
| 731 | |
| 732 | # Authentication methods we can handle in our preferred order: |
| 733 | if _have_cram_md5_support: |
| 734 | preferred_auths = ['CRAM-MD5', 'PLAIN', 'LOGIN'] |
| 735 | else: |
| 736 | preferred_auths = ['PLAIN', 'LOGIN'] |
| 737 | # We try the supported authentications in our preferred order, if |
| 738 | # the server supports them. |
| 739 | authlist = [auth for auth in preferred_auths |
| 740 | if auth in advertised_authlist] |
| 741 | if not authlist: |
| 742 | raise SMTPException("No suitable authentication method found.") |
| 743 | |
| 744 | # Some servers advertise authentication methods they don't really |
| 745 | # support, so if authentication fails, we continue until we've tried |
| 746 | # all methods. |
| 747 | self.user, self.password = user, password |
| 748 | for authmethod in authlist: |
| 749 | method_name = 'auth_' + authmethod.lower().replace('-', '_') |
| 750 | try: |
| 751 | (code, resp) = self.auth( |
| 752 | authmethod, getattr(self, method_name), |
| 753 | initial_response_ok=initial_response_ok) |