Python Forum
getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail (/thread-5180.html)



getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail - jainpratik163 - Sep-21-2017

i am trying to read outlook mail and getting below error while running the code

Error:
[quote]Traceback (most recent call last): File "read_mail.py", line 10, in <module> body_content = message.body File "C:\Program Files\Python35\lib\site-packages\win32com\client\__init__.py", line 473, in __getattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._MailItem instance at 0x1940794795848>' object has no attribute 'body'[/quote]
and below is my code which i am running.

import win32com.client
 
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
 
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print (body_content)
and i am using
Quote:python 3.5.2



RE: getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail - buran - Sep-21-2017

It is Body, not body


RE: getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail - jainpratik163 - Sep-21-2017

thanks it is working now..
but i have one doubt previously that code with
Quote:body
was working.


RE: getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail - buran - Sep-21-2017

Given the CamelCase naming convention used in win32com I doubt it ever worked:-)