4

In the Google API for python to send an email, https://developers.google.com/gmail/api/guides/sending you can find this method

def send_message(service, user_id, message):

  try:
    message = (service.users().messages().send(userId=user_id, body=message)
               .execute())
    print 'Message Id: %s' % message['id']
    return message
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

I am following that tutorial, and I have already followed another tutorial for getting the authentication, but my question is what to pass for this service variable. how to define it?

That page says nothing about it

Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253

1 Answers1

1

Here's an excerpt from a Quickstart example provided by Google.

import httplib2
from apiclient import discovery

def main():
    """Shows basic usage of the Gmail API.

    Creates a Gmail API service object.
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

In their example they generate the OAuth credentials using a client secret JSON file generated by their application. How you generate those credentials really depends on how you want your application to work.

ctp_9
  • 338
  • 2
  • 10