Python Forum
getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library._Mail
#1
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
Reply
#2
It is Body, not body
Reply
#3
thanks it is working now..
but i have one doubt previously that code with
Quote:body
was working.
Reply
#4
Given the CamelCase naming convention used in win32com I doubt it ever worked:-)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,530 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Search Outlook Inbox for set of values cubangt 1 975 Jun-28-2023, 09:29 PM
Last Post: cubangt
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,385 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,665 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Save image from outlook email cubangt 1 647 Jun-07-2023, 06:52 PM
Last Post: cubangt
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,213 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,300 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,494 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  Microsoft text phone verifying account cito 2 947 Jul-21-2022, 12:16 PM
Last Post: cito
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 6,968 Jul-06-2022, 10:55 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020