1

I am trying to download attachments from outlook- in azure databricks .The code was working fine earlier however from last couple of days , the code is failing with message login failed ,even though the credentials are correct.

I am using imaplib library but it is failing.

        import email, imaplib
    import os
    from sqlalchemy import create_engine
    import urllib
    import pyodbc
    import pandas as pd
    import zipfile
    import datetime
    from datetime import date
    from email.parser import HeaderParser
    server = 'outlook.office365.com'
    user = user
    password = *****
    subject = [subject]
    def connect(server, user, password):
        m = imaplib.IMAP4_SSL(server)
        m.login(user, password)
        m.select()
        return m
    def downloaAttachmentsInEmail(m, emailid, outputdir):
        resp, data = m.fetch(emailid, "(BODY.PEEK[])")
        email_body = data[0][1]
        SucessFailure = True
        if mail.get_content_maintype() != 'multipart':
                 return
        for part in mail.walk():
              if part.get_content_maintype() != 'multipart' and part.get('Content-Disposition') is not None:
                print('inside download')
                filename = part.get_filename()
                print(filename)```
  • 1
    What code have you tried so far? Could you be more specific? – Eugene Astafiev Jan 23 '23 at 13:27
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 23 '23 at 19:49
  • Microsoft disabled basic auth earlier this month: https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-deprecation-in-exchange-online-time-s-up/ba-p/3695312 – GammaGames Jan 26 '23 at 23:58
  • I made a walkthrough on working with oauth2: https://stackoverflow.com/questions/75264107/authenticate-with-exchange-to-access-email-inbox-with-imaplib/75264108#75264108 – GammaGames Jan 27 '23 at 22:55

0 Answers0