Home > Blockchain >  Python Exchangelib: Automate Enabling Attachments Due to Default Security Settings
Python Exchangelib: Automate Enabling Attachments Due to Default Security Settings

Time:09-01

I have an Exchange mailbox for python/exchangelib to scan emails from the Inbox and download select attachments for additional processing. It runs fine. However, recently one recurring email from the same sender that includes an Excel spreadsheet has the attachment disabled for what look like default security settings. As such Python skips this attachment, affecting the downstream data loads.

Once I use Outlook to manually "move" the email to the Inbox (odd because that's where it already is), the attachment is enabled and becomes available for the script to process. I've tried such things as right-clicking the email in Outlook and choosing Junk > Never Block Sender, but this has no effect.

Is there any way to automate this attachment enabling?

CodePudding user response:

Turns out this email WAS in the junk folder. My attempts to "Never Block Sender/Domain...." using Outlook failed. I even added a rule to move it to the inbox. Nada. However, I added a junk folder sweep to my python process, and it worked! No one has really even viewed this post, so I feel like I'm talking to myself, but hey, problem solved. For funzies, here's the partial code...

def box_unjunk():
  global exch, account, startdate, enddate, tz
  print('##### Checking for emails identified as junk...')
  mail_inbox = account.inbox 
  mail_junk  = account.junk

  for item in mail_junk.filter(
    datetime_received__range=(
      tz.localize(exch.EWSDateTime(startdate.year, startdate.month, startdate.day)),
      tz.localize(exch.EWSDateTime(enddate.year, enddate.month, enddate.day, enddate.hour, enddate.minute, enddate.second))
      )).order_by('-datetime_received'):
    if (re.fullmatch(r'.*', item.subject.lower())): 
      print('    Moving email with subject:', item.subject, 'to Inbox folder')
      item.move(mail_inbox)
  • Related