Python Forum

Full Version: [Outlook] How to delete items from To-Do List?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I searched the archives and elsewhere with "outlook to-do list items delete", but came back empty handed.

I'm using Outlook 2007, and need to delete items in the To-Do List section that match a given pattern. How do I do this?

import sys
import win32com.client
import re

olFolderTodo = 28

outlook = win32com.client.Dispatch("Outlook.Application")
ns = outlook.GetNamespace("MAPI")
todo_folder = ns.GetDefaultFolder(olFolderTodo)
todo_items = todo_folder.Items

p = re.compile('(https://twitter\.com/.+?)\?.+')

for i in range(0, 0 + len(todo_items)):
    item = u'{0}'.format(todo_items[i])
    m = p.search(item)
    if m:
        print(m.group(1))

        #HERE
Thank you.
This might sound dumb, but are the items actually in outlook? Or are they stored on the imap/exchange server?

I don't know about to-do items, but Outlook does weird things with iCal events, like copying them locally and ignoring remote changes.

That said, it looks like most of your code is copied from this stack overflow answer: https://stackoverflow.com/a/19044929
Which links to this article: https://www.add-in-express.com/creating-...et-delete/

The article has examples of how to delete tasks. ie: it might be as simple as item.Delete().