I want to extract the whole message body of mail using gmail api. Right now i am using \'snippets\' but i need the entire text. I searched and found that it\'s something to
Use Users.messages.get from the docs where there's a Python snippet:
import base64
import email
from apiclient import errors
def GetMessage(service, user_id, msg_id):
try:
message = service.users().messages().get(userId=user_id, id=msg_id).execute()
print 'Message snippet: %s' % message['snippet']
return message
except errors.HttpError, error:
print 'An error occurred: %s' % error
def GetMimeMessage(service, user_id, msg_id):
try:
message = service.users().messages().get(userId=user_id, id=msg_id, format='raw').execute()
print 'Message snippet: %s' % message['snippet']
msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
mime_msg = email.message_from_string(msg_str)
return mime_msg
except errors.HttpError, error:
print 'An error occurred: %s' % error
What your trying to access is the payload.body or if you want to go further, payload.body.data.