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)```