(4096, «Microsoft Outlook», «Операция не удалась.», Нет, 0, -2147287037) ошибка при сохранении электронного письма на лоPython

Программы на Python
Anonymous
(4096, «Microsoft Outlook», «Операция не удалась.», Нет, 0, -2147287037) ошибка при сохранении электронного письма на ло

Сообщение Anonymous »

Я пытаюсь загрузить несколько писем из папки Outlook на локальный компьютер в виде файлов .msg, используя следующий код.

Код: Выделить всё

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 на том же самом. Трассировка стека приведена ниже:

Код: Выделить всё

---------------------------------------------------------------------------
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

Вернуться в «Python»