I am trying to send a message via the Google API in python, and am trying to run an example taken almost directly from the Google example page.
def CreateMessage(sender, to, subject, message_text):
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string().replace('message','resource').encode('ascii'))}
But when I try to send it
message = CreateMessage(sender, to, subject, message_text)
message = service.users().messages().send(body=list(message),userId='me').execute()
I get the error : "'raw' RFC822 payload message string or uploading message via /upload/* URL required"
From other posts it seems like Google is expecting an attachment. Is there something wrong with the MIMEText making it expect one, and if so, how do I fix it?