dubsauce
dubsauce

Reputation: 43

Exchangelib office365 auth fail: infinite loop

I'm trying to configure python exchangelib for Office365 but somehow it doesn't work, not sure if it's because of the corporate firewalls, or misconfiguration.

I've tried 40+ configs, with and without autodiscover links.

I'm trying to connect to a group mailbox not a private mail account.

Code:

from exchangelib import DELEGATE, Account, Credentials, IMPERSONATION, EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, Mailbox, Attendee, Q
from exchangelib.folders import ExtendedProperty, FileAttachment, ItemAttachment, HTMLBody
import logging
config = Configuration(
#service_endpoint='https://triedthisservertoo.com/EWS/Exchange.asmx', 
    server='localSMTPserver',
    credentials = Credentials(
    username='[email protected]',
    password='topsecret'),
    auth_type=NTLM,
    verify_ssl=False
    )

account = Account(
    primary_smtp_address='[email protected]',
    autodiscover=False, 
    config=config,
    access_type=IMPERSONATION)

logging.basicConfig(level=logging.DEBUG)
pprint (account.folders())

Output(infinite loop, apparently):

C:\Users\mcindea\Downloads\dist\exchangelib-1.7.6>python test.py
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c InsecureRequestWarning)
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c  InsecureRequestWarning)
C:\Users\mcindea\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding c  InsecureRequestWarning)

Upvotes: 0

Views: 2556

Answers (1)

dubsauce
dubsauce

Reputation: 43

Found the answer, it was a goofy config that MS used to create our accounts.Username must be in the format [email protected].

I forgot the "on" subdomain. If anybody needs the script ( search emails in Exchange servers by subject, and save the attachments localy), it can be found here:

https://github.com/psychameleon/Office365GrabMail/blob/master/email-grabber.py

Upvotes: 2

Related Questions