Код: Выделить всё
messages = source_folder.Items
for message in messages:
# Estimate the size of the email
size = message.Size
if size < 5 * 1024 * 1024: # 5MB
# Save the email as a .msg file
subject = message.Subject.replace(":", "").replace("\\", "").replace("/", "").replace("*", "").replace("?", "").replace("\"", "").replace("", "").replace("|", "")
received_time = message.ReceivedTime.strftime("%Y%m%d%H%M%S")
file_name = f"{subject}.msg"
file_path = os.path.join(email_dir, file_name)
time.sleep(10)
message.SaveAs(file_path) # 3 corresponds to the .msg format
print(f"Emails have been saved to {email_dir}")
Код: Выделить всё
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
Cell In[17], line 12
10 file_path = os.path.join(email_dir, file_name)
11 time.sleep(10)
---> 12 message.SaveAs(file_path) # 3 corresponds to the .msg format
13 if i == 0:
14 break
File :2, in SaveAs(self, Path, Type)
com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The operation failed.', None, 0, -2147287037), None)
Подробнее здесь: https://stackoverflow.com/questions/786 ... 7037-error