pythonemailexchange-serverpop3poplib

Poplib Microsoft Exchange logon error


I have the following code connecting to a Microsoft exchange server (2010 version). This is the snipped I'm having trouble with. (it works with other email servers/local mail server made for test). The user/password are validated and are, for this purpose, hard coded hence no miss spelling problems. I use this email account in microsoft outlook so it's valid on the server side too.

self.connection = poplib.POP3_SSL('my.email.server')
self.connection.set_debuglevel(2)
print self.connection.getwelcome()
self.connection.user('myuser')
self.connection.pass_('mypassword')

The result is the following:

+OK The Microsoft Exchange POP3 service is ready.
*cmd* 'USER myuser'
*put* 'USER myuser'
*get* '+OK\r\n'
*resp* '+OK'
*cmd* 'PASS mypassword'
*put* 'PASS mypassword'
*get* '-ERR Logon failure: unknown user name or bad password.\r\n'
*resp* '-ERR Logon failure: unknown user name or bad password.'
Traceback (most recent call last):
  File "getMail.py", line 237, in <module>
    start_deamon()
  File "getMail.py", line 229, in start_deamon
    deamon.process_email()
  File "getMail.py", line 63, in process_email
    self.connection.pass_('password')
  File "C:\Python27\lib\poplib.py", line 189, in pass_
    return self._shortcmd('PASS %s' % pswd)
  File "C:\Python27\lib\poplib.py", line 152, in _shortcmd
    return self._getresp()
  File "C:\Python27\lib\poplib.py", line 128, in _getresp
    raise error_proto(resp)
poplib.error_proto: -ERR Logon failure: unknown user name or bad password.

The error is pretty obvious, but I'm sure that the user/pass are real, I've tried to connect via POP and POP_SSL the result is the same. I do get the welcome message so I know the server is UP and supports POP3/POP3_SSL and the port is correct (which is default). I'm not behind any firewall/proxy the server is on the same network.

What can be the error? Is there any other way to connect to Microsoft Exchange just using POP3? (or if needed IPMA).


Solution

  • Looks like the error it's not programmatic. The code itself is alright both POP3 and POP3_SSL.

    The issue is actually running the code on a machine which wasn't authenticated on the network, so the exchange server never allowed the login.