SMTPAuthenticationError

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramashish Baranwal

    SMTPAuthenticationError

    Hi,

    I am trying to send a mail using smtplib. My server requires me to
    authenticate, for this I'm using SMTP.login function. However it
    fails-
    >>server = smtplib.SMTP(ho st='mail.domain ', port=25)
    >>server.login( 'username', 'password')
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.4/smtplib.py", line 587, in login
    raise SMTPAuthenticat ionError(code, resp)
    smtplib.SMTPAut henticationErro r: (535, 'authorization failed
    (#5.7.0)')

    I am sure that I am giving the correct credentials. The same works in
    Thunderbird. Am I missing something here or am I supposed to use some
    other library for this?

    Thanks in advance,
    Ram

  • Larry Bates

    #2
    Re: SMTPAuthenticat ionError

    Ramashish Baranwal wrote:
    Hi,
    >
    I am trying to send a mail using smtplib. My server requires me to
    authenticate, for this I'm using SMTP.login function. However it
    fails-
    >
    >>>server = smtplib.SMTP(ho st='mail.domain ', port=25)
    >>>server.login ('username', 'password')
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.4/smtplib.py", line 587, in login
    raise SMTPAuthenticat ionError(code, resp)
    smtplib.SMTPAut henticationErro r: (535, 'authorization failed
    (#5.7.0)')
    >
    I am sure that I am giving the correct credentials. The same works in
    Thunderbird. Am I missing something here or am I supposed to use some
    other library for this?
    >
    Thanks in advance,
    Ram
    >
    Are you sure that your SMTP server uses this type of authentication?
    Some SMTP servers use POP3 followed by SMTP to authenticate instead.


    use telnet to verify, this link might help.



    -Larry

    Comment

    • Ramashish Baranwal

      #3
      Re: SMTPAuthenticat ionError

      >
      I am trying to send a mail using smtplib. My server requires me to
      authenticate, for this I'm using SMTP.login function. However it
      fails-
      >
      >>server = smtplib.SMTP(ho st='mail.domain ', port=25)
      >>server.login( 'username', 'password')
      Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "/usr/lib/python2.4/smtplib.py", line 587, in login
      raise SMTPAuthenticat ionError(code, resp)
      smtplib.SMTPAut henticationErro r: (535, 'authorization failed
      (#5.7.0)')
      >
      I am sure that I am giving the correct credentials. The same works in
      Thunderbird. Am I missing something here or am I supposed to use some
      other library for this?
      >
      Thanks in advance,
      Ram
      >
      Are you sure that your SMTP server uses this type of authentication?
      Some SMTP servers use POP3 followed by SMTP to authenticate instead.
      >
      use telnet to verify, this link might help.
      >
      http://www.computerperformance.co.uk...nge2003_SMTP_A...
      >
      Hi Larry,

      Thanks for the reply. I have worked according to the steps in the link
      you provided. From that it seems my server accepts base64 encoded
      username and password. I am able to login this way. How to give the
      same in smtplib?

      Ram

      Comment

      • Ramashish Baranwal

        #4
        Re: SMTPAuthenticat ionError

        To help debug this, you may want to try the following.
        >
        1) Copy smptlib.py into your local directory. On my
        box, you can find it here, or import sys; print
        sys.path to help find it on your box:
        >
        /usr/local/lib/python2.3
        >
        2) Go the login() method, add some print statements
        there to see what's going on.
        >
        I admit to not being an SMTP expert nor fully
        understanding the code at first glance, but here is
        some code iin smtplib.py that suggests you're close to
        getting this working, to the extent that your server
        wants base64 encoding:
        >
        def encode_cram_md5 (challenge, user,
        password):
        challenge = base64.decodest ring(challenge)
        response = user + " " +
        hmac.HMAC(passw ord, challenge).hexd igest()
        return encode_base64(r esponse, eol="")
        >
        Hope this helps.
        Thanks Steve, that helped a lot. smtplib was trying to a CRAM-MD5 auth
        which wasn't working. I don't know why. But when I made it do a LOGIN
        auth by changing its preferred_auth list, it worked. Login has its own
        preferred list of auth methods which is nice except that not all
        servers which advertise a particular method may be capable of handling
        that.

        It would have been good if there was optionally a way to specify in
        login() what method to use. For now, I am simply going to derive SMTP
        to form a class that does LOGIN auth.

        Ram

        Comment

        Working...