Home > Mobile >  Outlook Sender mail issue
Outlook Sender mail issue

Time:06-14

I am trying to get an email body on basis of a particular sender name from the outlook inbox by using the win32.com client. However, it only return the COMObject Restrict Here my code.

import win32com.client as win32
import numpy as np


outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI")

folder = outlook.GetDefaultFolder(6)
messagess = folder.Items

messages = messagess.Restrict("[SenderEmailAddress] = '[email protected]'")
print(messages)
arr=[]
for m in messages:
    arr=m.Body
    print(arr)

CodePudding user response:

The Items.Restrict method from the Outlook object model returns a new collection containing all of the items from the original that match the filter (an instance of the Items class) which is a COM object under the hood. You may try to use methods and properties of the Items class in the code to make sure the result is valid.

You can read more about that method in the How To: Use Restrict method to retrieve Outlook mail items from a folder article.

CodePudding user response:

print() deals with scalar (string, integer, boolean, etc.) values. It does not know anything about any particular COM object - the best it can do is output the object's type name ("COMObject"). There is no way it can know anything about the Items Outlook object. It is your responsibility to maker sense of it by actually looping through the collection and printing values that make sense in your particular case.

  • Related