MCPcopy Index your code
hub / github.com/python/cpython / login

Method login

Lib/smtplib.py:696–762  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 8

emitMethod · 0.95
testAUTH_PLAINMethod · 0.95
testAUTH_LOGINMethod · 0.95
testAUTH_CRAM_MD5Method · 0.95
testAUTH_multipleMethod · 0.95

Calls 8

has_extnMethod · 0.95
authMethod · 0.95
SMTPExceptionClass · 0.85
splitMethod · 0.45
replaceMethod · 0.45
lowerMethod · 0.45

Tested by 7

testAUTH_PLAINMethod · 0.76
testAUTH_LOGINMethod · 0.76
testAUTH_CRAM_MD5Method · 0.76
testAUTH_multipleMethod · 0.76