1

I have a code, which sends a new email to the chosen recipients. The email is created based on a received email, which is in the inbox.

For the email sending I use the Win32 python library.

However, since a brand new email is being created, the email from which the new email is created left 'unseen' in the inbox.

How can I set the original email to 'seen' with code?

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.

0m3r
  • 12,286
  • 15
  • 35
  • 71
Elod
  • 11
  • 1

2 Answers2

0

the email from which the new email is created left 'unseen' in the inbox.

You just need to set the MailItem.UnRead property to false on that item. The property returns or sets a boolean value that is true if the Outlook item has not been opened (read).

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
0

Try inbox.Items[i].UnRead = False after mail.Send()

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)
0m3r
  • 12,286
  • 15
  • 35
  • 71