Monday, September 20, 2021

Accessing a folder by name and looping through items inside it in outlook using python

 import win32com.client as client
import datetime,time
from os import path

outlook=client.Dispatch("Outlook.Application")

count = 0
olFolder = outlook.GetNamespace("MAPI").Folders("allsourav@hotmail.com").Folders("Sent Items")
#now let us loop through the mail items in that folder

for itmmail in olFolder.Items:
    

    if (itmmail.SentOnBehalfOfName =="allsourav@hotmail.com"):
        count = count + 1

print(count)

##Dim itmcount As Integer
itmcount = olFolder.Items.count
print(itmcount)
count = 0
##Dim x As Integer
##
##'reading mail older to newer
##
for x in range(1,itmcount):
##
    if (olFolder.Items(x).SentOnBehalfOfName == "allsourav@hotmail.com"):
        count = count + 1

print(count)
##
count = 0
##'reading mail in reverse order ,new to old
##
for x in range(itmcount,1,-1):
    if (olFolder.Items(x).SentOnBehalfOfName == "allsourav@hotmail.com"):
        count = count + 1
##End If
##Next x
print(count)

No comments:

Post a Comment