Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29767

Trying to send emails with Gmail API

$
0
0

I've been followning tutorials and reading articles trying to learn how to make sense of the gmail API using python 3.I've gotten stuck on the messages.send method.

My authentication works but my CreateMessage function is throwing an error.

Here is my code so far:

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_bytes())}    message = CreateMessage('xxxxxxxx@gmail.com','xxxxxxxx@gmail.com','subject','message text')    service = build('gmail', 'v1', credentials=creds)    created_message = service.users().messages().send(userId='me', body=message).execute()

The error it's throwing is "TypeError: Object of type bytes is not JSON serializable"Any and all contrusctive criticism is welcome. Or any quality tutorials on the subject you can direct me to! Thank you.


Viewing all articles
Browse latest Browse all 29767

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>