Search code examples
pythonpython-2.7pop3poplib

Python 2.7 POP3_SSL Error connecting to Outlook Mailbox?


Some background: I am working on learning how to convert an app that uses a POP3 connection to use OAuth since Microsoft is dropping support for basic authentication in October. Initially I was using just POP3, but swapped to POP3_SSL after not being able to even enter a username. However, I've run across an issue authenticating with the password

import poplib
email_address = '[email protected]'
password = 'redacted'
pop3_server = 'outlook.office.com'
server = poplib.POP3(pop3_server)

server.set_debuglevel(1)

pop3_server_welcome_msg = server.getwelcome().decode('utf-8')

print(server.getwelcome().decode('utf-8'))

server.user(user=email_address)
server.pass_(password)

The error:

+OK The Microsoft Exchange POP3 service is ready. [UwBOADcAUABSADAANABDAEEAMAAxADkANgAuAG4AYQBtAHAAcgBkADAANAAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
*cmd* 'USER [email protected]'
*cmd* 'PASS redacted'
Traceback (most recent call last):
  File "testScript.py", line 89, in <module>
    server.pass_(password)
  File "c:\python27\lib\poplib.py", line 197, in pass_
    return self._shortcmd('PASS %s' % pswd)
   File "c:\python27\lib\poplib.py", line 160, in _shortcmd
     return self._getresp()
  File "c:\python27\lib\poplib.py", line 136, in _getresp
    raise error_proto(resp)
poplib.error_proto: -ERR Logon failure: unknown user name or bad password.

Copied project from here

Logging into the account via outlook the password works, but doesn't when running the script. If there is a step I have missed, please let me know. Thanks!


Solution

  • As it turns out, I was given the incorrect test email. The one I was using had advanced auth in place. Using an account with only basic auth works fine. Going to close this question.