データを操作できるように、exchange/Outlook プロファイルのフォルダー内の電子メールの内容を読み取る短いプログラムを作成しようとしています。しかし、python と exchange/Outlook の統合に関する多くの情報を見つけるのに問題があります。多くのものは、非常に古いか、ドキュメントがないか、説明されていません。いくつかのスニペットを試しましたが、同じエラーが発生しているようです。私はTim Goldenのコードを試しました:
import win32com.client
session = win32com.client.gencache.EnsureDispatch ("MAPI.Session")
#
# Leave blank to be prompted for a session, or use
# your own profile name if not "Outlook". It is also
# possible to pull the default profile from the registry.
#
session.Logon ("Outlook")
messages = session.Inbox.Messages
#
# Although the inbox_messages collection can be accessed
# via getitem-style calls (inbox_messages[1] etc.) this
# is the recommended approach from Microsoft since the
# Inbox can mutate while you're iterating.
#
message = messages.GetFirst ()
while message:
print message.Subject
message = messages.GetNext ()
ただし、エラーが発生します。
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
私のプロファイル名が何であるかわからないので、試してみました:
session.Logon()
プロンプトが表示されますが、それも機能しませんでした (同じエラー)。また、Outlookを開いた状態と閉じた状態の両方で試しましたが、どちらも何も変わりませんでした。