繁体   English   中英

win32com使用Python访问outlook

[英]Using Python to access outlook with win32com

我正在努力使用 win32com.client 将 python 与 outlook 集成。

我要做的就是从 outlook 获取最新的 email 并(目前)检索并打印附件的名称

我尝试使用的代码:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespcae("MAPI")

inbox = outlook.GetDefaultFolder(6)

message = inbox.GetLast()

att = message.Attachmets 

print (att.filename)

Output

com_error: (-2147221005, 'Invalid class string', None, None)

任何帮助将不胜感激。

错误是 Outlook 在系统上找不到,但您也拼错了GetNamespace ,您有GetNamespcae

inbox.GetLast()更改为messages = inbox.Items然后message = messages.GetLast()

例子

import win32com.client

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

inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
messages.Sort('[ReceivedTime]', False)
message = messages.GetLast()

for attachment in message.Attachments:
    print(attachment.FileName)

这是过滤器https://stackoverflow.com/a/57931132/4539709的另一个示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM