I have tried researching this but a lot of the times it is for Gmail and for other online services and the ones I did find that sort of meet my needs they were quite a few years old and didn't work:
Downloading multiple attachments using imaplib --- 9 years old Downloading excel attachments using imaplib --- nearly 3 years old
The https://docs.python.org/3/library/imaplib.html was quite insightful but wasn't able to implement what I had learned.
Tried manipulating the code to fit my requirements but keep getting errors:
m.login(user, password)
File "C:\Users\uk20071143\AppData\Local\Programs\Python\Python38-32\lib\imaplib.py", line 603, in login
raise self.error(dat[-1])
imaplib.IMAP4.error: b'LOGIN failed.'
Currently, I have an excel that has been sent out to project managers where once they press submit I am sent an email with the work they want to be submitted, because of the changes that are usually made I leave combining them to the end.
Using python I am trying to automate downloading the Excel attachments from all emails that have a subject name of Matrix to a designated folder where I run another piece of VBA code that will pull the newest files into one output excel.
I am using Microsoft Office 365 ProPlus, I was trying with the default folder numbers but didn't work, not sure whether this was correct but Inbox [6]??
Annoyingly only ever seem to find perfect Gmail codes: https://gist.github.com/baali/2633554
server = 'outlook.office365.com'
user = input('email: ')
password = ('password: ')
outputdir = 'C:/Users'
subject = 'Matrix'
def connect(server, user, password):
conn = imaplib.IMAP4_SSL(server)
conn.login(user, password)
conn.select()
return conn
Above is the sort of way I want to connect but it fails to output anything when testing or it just fails.
If anyone has a code or any idea on how to download attachments from outlook using python that using the subject and subject body 'Matrix' as reference. well that would be amazing
Thanks