tandian
tandian

Reputation: 11

export Outlook emails to PST with Python win32com.client

from pathlib import Path
import win32com.client

# Creation du repertoire
output_dir = Path.cwd() / "Backup"
output_dir.mkdir(parents=True, exist_ok=True)

# Acceder à outlook
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

# Recuperer la boite de reception
inbox = outlook.GetDefaultFolder(6)

# lien du chemin
pst = str(output_dir / "backup.pst")

# Export inbox folder to PST file
inbox.Export(pst)

I'm trying to export my inbox from Outlook as a pst file but I'm getting an error with the export method. Does anyone have an idea?

Upvotes: 1

Views: 344

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

Call Namespace.AddStoreEx (where Namespace is your outlook variable), find the new Store object in the Namespace.Stores collection, then copy the Inbox folder to the new store (inbox.CopyTo(Store.GetRootFolder()))

Upvotes: 0

Related Questions