1

So I'm having trouble finding what this error is:

smtplib.SMTPAuthenticationError: (235, 'welcome')

I can't find a clear answer what 235 is anywhere.

So I do something along the lines of the following:

s = smtplib.SMTP()
s.connect("smtp.myserver.com", 25)

With a reply of (220, 'Welcome to the 9x SMTP Server')

Then I do:

s.ehlo()

and get back

(250, 'p3\nAUTH LOGIN\nHELP')

I did this because the server doesn't support starttls

smtplib.SMTPException: STARTTLS extension not supported by server.

Then I try to log in:

>>> s.login("[email protected]", "password")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python27\lib\smtplib.py", line 608, in login
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (235, 'welcome')

I don't know what 235 means, but I get a welcome string. I'm really confused, I'm 100% sure my credentials are correct.

4
  • were you calling s.ehlo() before s.starttls()? Jul 23, 2014 at 16:26
  • In this example yes, but even if I call starttls before ehlo, I get the same error.
    – Matt M
    Jul 23, 2014 at 16:36
  • "235 2.7.0 Authentication Succeeded This response to the AUTH command indicates that the authentication was successful." - tools.ietf.org/html/rfc4954#section-6
    – Robᵩ
    Jul 23, 2014 at 20:09
  • Yes but python raises an error.
    – Matt M
    Jul 24, 2014 at 2:27

2 Answers 2

1

Your server's response to the AUTH LOGIN command is atypical, and perhaps non-standard.

The typical pattern is this:

C: AUTH LOGIN xxxx
S: 334 yyyy
C: zzzz
S: 235 welcome

Where C indicates the client, S indicates the server, xxxx is the base64-encoded user name, yyyy is an ignorable base64-encoded string, and zzzz is the base64-encoded password.

Your server is instead doing this:

C: AUTH LOGIN xxxx
S: 235 welcome

For whatever reason, your server doesn't appear to be interested in the password.

I do not know what configuration change you might need on your server. If you are interested in modifying smtplib.py, look for this code:

    elif authmethod == AUTH_LOGIN:
        (code, resp) = self.docmd("AUTH",
            "%s %s" % (AUTH_LOGIN, encode_base64(user, eol="")))
        if code != 334:
            raise SMTPAuthenticationError(code, resp)
        (code, resp) = self.docmd(encode_base64(password, eol=""))

and try something like this instead:

    # UNTESTED
    elif authmethod == AUTH_LOGIN:
        (code, resp) = self.docmd("AUTH",
            "%s %s" % (AUTH_LOGIN, encode_base64(user, eol="")))
        if code == 334:
            (code, resp) = self.docmd(encode_base64(password, eol=""))
        elif code != 235:
            raise SMTPAuthenticationError(code, resp)

On the other hand, modifying your program probably makes more sense. Try this:

#s.login("[email protected]", "password")
code, resp = s.docmd('AUTH LOGIN', encode_base64('[email protected]'))
if code==334:
    # Probably won't happen on "the 9x SMTP Server"
    code, resp = s.docmd(encode_base64('password'), '')
if code!=235:
    raise smtplib.SMTPAuthenticationError(code, resp)

Reference:

2
  • Thanks for your long post. It was really helpful. It didn't work unfortunately because I get a str object not having an attribute 'get_payload'
    – Matt M
    Jul 24, 2014 at 1:50
  • Or maybe there's a way to use my smtp server without requiring a password? I can't figure out the configuration at the moment. It would be cool to have an open SMTP.
    – Matt M
    Jul 24, 2014 at 2:07
0

Maybe you have to perform additional settings required by your SMTP. According to the documentation, since you are using ehlo you can perform such setup by changing s.esmtp_features dictionary.

Example:

s.esmtp_features["auth"] = "LOGIN DIGEST-MD5" # changing the authentication method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.