简体   繁体   English

如何使用 WIN32 python 在 Outlook 中将 email 设置为“已看到”?

[英]How to set an email to 'Seen' in Outlook with WIN32 python?

I have a code, which sends a new email to the chosen recipients.我有一个代码,它会向选定的收件人发送一个新的 email。 The email is created based on a received email, which is in the inbox. email 是根据收件箱中收到的 email 创建的。

For the email sending I use the Win32 python library.对于 email 发送,我使用 Win32 python 库。

However, since a brand new email is being created, the email from which the new email is created left 'unseen' in the inbox.然而,由于正在创建一个全新的 email,因此创建新 email 的 email 在收件箱中“看不见”。

How can I set the original email to 'seen' with code?如何使用代码将原始 email 设置为“可见”?

The code is something like this:代码是这样的:

if inbox.Items[i].UnRead == True:
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = mail_list
    mail.Subject = sub
    mail.HTMLbody = new_body
    mail.Send()
    print('The email was sent successfully!')

Thank you in advance.先感谢您。

the email from which the new email is created left 'unseen' in the inbox.从中创建新的 email 的 email 在收件箱中“看不见”。

You just need to set the MailItem.UnRead property to false on that item.您只需将该项目的MailItem.UnRead属性设置为 false。 The property returns or sets a boolean value that is true if the Outlook item has not been opened (read).该属性返回或设置一个 boolean 值,如果 Outlook 项尚未打开(读取)则该值为真。

Try inbox.Items[i].UnRead = False after mail.Send()mail.Send()之后尝试inbox.Items[i].UnRead = False

Example例子

import win32com.client


def send_new_email(inbox):
    for item in inbox.items:
        if item.UnRead:
            print(item.Subject)
            new_email = outlook.CreateItem(0)
            new_email.Display()
            item.UnRead = False


if __name__ == "__main__":
    outlook = win32com.client.Dispatch("outlook.Application")
    olNs = outlook.GetNamespace("MAPI")
    inbox = olNs.GetDefaultFolder(6)
    send_new_email(inbox)

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

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