繁体   English   中英

如何与Outlook中的特定电子邮件进行交互?

[英]How to interact with a specific email in outlook?

我试图阅读在Outlook中收到的电子邮件的正文,但是我只能从我的第一个电子邮件地址阅读我的电子邮件。 有没有办法选择应该阅读的电子邮件地址? 例如,例如,我的Outlook帐户中的电子邮件地址地址是?

import win32com.client

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

inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetFirst()
body = message.body
subject = message.subject
sender = message.sender

while message:
    print("Subject: " + subject
    + "\tSender: " + str(sender)
    + "\nBody: " + body
    + "\n"
    )
    message = messages.GetNext()

我已经尝试给“收件箱”添加第二个参数,因为我认为可以选择该电子邮件,但这只会给我带来错误。

inbox = outlook.GetDefaultFolder(4, 6)

那么,有没有一种聪明又容易的方法来选择您想要阅读的电子邮件地址?

您可以登录到指定的邮件配置文件:
(示例代码取自Tim Golden的Python Stuff

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

您可以使用帐户的DeliveryStore属性获取其收件箱。 例如:

Sub ResolveName()
Dim ns As NameSpace
Set ns = Application.Session
Dim acc As Account
Dim f As Folder

For Each acc In ns.accounts
    MsgBox acc.UserName
    If acc = "text@outlook.com" Then
    Set f = acc.DeliveryStore.GetDefaultFolder(olFolderInbox)
    MsgBox f.Items.count

End If
Next
End Sub

您可以使用acc =“ text@outlook.com”或acc.UserName属性进行过滤。

暂无
暂无

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

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