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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.