Matt M
Matt M

Reputation: 149

trouble sending email using python SMTP

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.

Upvotes: 1

Views: 1045

Answers (2)

Robᵩ
Robᵩ

Reputation: 168626

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:

Upvotes: 1

Fabio Menegazzo
Fabio Menegazzo

Reputation: 1249

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

Upvotes: 0

Related Questions