I am writing a python code to read emails on Microsoft Outlook, looking for files attached (any file *.msg), read these .msg files and grab any URL contained in the body of the message.
So, the final idea is:
Read Emails -> Is there attachments? -> If yes -> Is the file extension equals to .msg? -> If yes, read this file and grab URL link.
First, I wrote a simple python script just to read the emails and log the name of the attached files. However, when there is a different file attached (like .mp3 for instance), my script returns the error:
I tried to ignore it using the code below, but I got the same error:
So, the final idea is:
Read Emails -> Is there attachments? -> If yes -> Is the file extension equals to .msg? -> If yes, read this file and grab URL link.
First, I wrote a simple python script just to read the emails and log the name of the attached files. However, when there is a different file attached (like .mp3 for instance), my script returns the error:
Error:Traceback (most recent call last):
File "phishing-mailbox.py", line 63, in <module>
if str(attch.FileName).endswith('.mp3') is True:
File "C:\Program Files\Python36\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Outlook cannot perform this action on this type of attachment.', None, 0, -2147467259), None)
I am using the library win32com in my script. So, I would like to know if anyone knows how to handle this Outlook return error?I tried to ignore it using the code below, but I got the same error:
if str(attch.FileName).endswith('.mp3') is True: print("File attached is .mp3!") continue