I am trying to build a database with all the emails.
But I get the Error:
ErrorServerBusy: The server cannot service this request right now. Try again later.
Is there any way to work with the throttling policy of ews? One month of emails do work but when I exceed some not known barrier it gets interrupted. Are there any other ways to prevent the throttling policies? I thought about implementing time.sleep(), but how could I find out how for how long I need to wait after how many emails to make it work?
shared_postboxes= [some accounts here]
credentials = Credentials(username=my username, password=my password)
config = Configuration(retry_policy=FaultTolerance(max_wait=600), credentials=credentials)
for shared_postbox in tqdm(shared_postboxes):
account = Account(shared_postbox, credentials=credentials, autodiscover=True)
top_folder = account.root
email_folders = [f for f in top_folder.walk() if isinstance(f, Messages)]
for folder in tqdm(email_folders):
for m in folder.all().only('text_body', 'datetime_received',"sender").filter(datetime_received__range=(start_of_month,end_of_month), sender__exists=True).order_by('-datetime_received'):
try:
senderdomain = ExtractingDomain(m.sender.email_address)
except:
print("could not extract domain")
else:
if senderdomain in domains_of_interest:
postboxname = account.identity.primary_smtp_address
body = m.text_body
emails.append(body)
senders.append(senderdomain)
postbox.append(postboxname)
received.append(m.datetime_received)
account.protocol.close()