Hi,
don't know if that's something you could use, but I have used Python to script Outlook (in online-mode) to shuffle around mail into different Folders. That's basically using the VBA API https://docs.microsoft.com/en-us/office/vba/api/overview/outlook , but in Python...
Here is one that sorts old Items from a default folder into yearly archive folders...
import win32com.client
import time
from enum import Enum
class OlDefaultFolders(Enum):
DELETED_ITEMS = 3
OUTBOX = 4
SENT_MAIL = 5
INBOX = 6
CALENDAR = 9
CONTACTS = 10
JOURNAL = 11
NOTES = 12
TASKS = 13
DRAFTS = 16
CONFLICTS = 19
SYNC_ISSUES = 20
LOCAL_FAILS = 21
SERVER_FAILS = 22
JUNK = 23
RSS = 25
TODO = 28
SUGGESTED_CONTACTS = 30
def print_folder(folder):
print("{:s} ({:d} subfolders, {:d} items)".format(
folder.Name,
folder.Folders.Count,
folder.Items.Count
))
def print_mailitem(mail):
#print(mail.Class)
print("Item\n MAIL FROM: {:s}\n RCPT TO: {:s}\n DATE: {:s}\n SUBJECT: {:s}\n {:s}".format(
mail.SenderEmailAddress if mail.Sender is not None else "",
mail.To,
mail.ReceivedTime.strftime("%d.%m.%Y %H:%M"),
mail.Subject,
mail.Body[:80].replace('\n', '')
))
class MapiClient:
def __init__(self):
self.application = win32com.client.Dispatch("Outlook.Application")
self.client = self.application.GetNamespace("MAPI")
def mapi(self):
return self.client
def inbox(self):
return self.client.GetDefaultFolder(OlDefaultFolders.INBOX.value)
def archive(self):
return self.client.DefaultStore.GetRootFolder().Folders("Archiv")
YEAR = "2016"
client = MapiClient()
print("MAPI SESSION - current profile: {:s}".format(client.mapi().CurrentProfileName))
print_folder(client.inbox())
print_folder(client.archive())
restriction = "[ReceivedTime] >= '{:s}' AND [ReceivedTime] <= '{:s}'".format(
"01.01.{:s} 00:00".format(YEAR),
"31.12.{:s} 23:59".format(YEAR)
)
archiveFolder = client.archive().Folders(YEAR)
print_folder(archiveFolder)
restrictedItems = client.inbox().Items.Restrict(restriction)
print(" {:d} items in date range".format(restrictedItems.Count))
for item in restrictedItems:
if item.Class != 43:
continue
#print_mailitem(item)
print(item, end=" ")
try:
item.Move(archiveFolder)
print("- OK")
time.sleep(0.1)
except Exception as err:
print("- !! {:s}".format(str(err)))
pass