Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change signatures using python gmail api?

Tags:

python

gmail

api

Python beginner here - I'm trying to program in python so I can change our users' signature for our organization. I'm having trouble following this guide.

The code examples are clear but how to get started is not. I vaguely understand that I need to use oauth2 like here, and fully understand how to create a token under the developers console.

Can someone give me a code snippet to connect using oauth2 with "Fake Token" and retrieve everyone's account email and their signature settings? This would help me use other methods from the classes mentioned in the DOC.

like image 986
JuniorPenguin Avatar asked Jun 06 '15 07:06

JuniorPenguin


People also ask

How do I change the HTML signature in Gmail?

Under the General tab in Settings, scroll down till you find the Signature section. Click inside the Signature edit box and go to Edit > Paste to paste in the HTML you have stored in the clipboard (Command+V). Click “Save Changes” right below the Signature edit box.


1 Answers

There are a few examples that demonstrate using python and assume that you have installed the following modules: gdata, oauth2client, and/or apiclient. Use these links to install them Google API Client Library for Python and Google Data Python Library.

There are samples spread across the API and developer site but these were the most helpful.

  1. Quickstart for Python provides a way to get credentials and uses the api-client module
  2. The documentation has a code snippet that shows how to modify a Signature using Python libs.

    import gdata.apps.emailsettings.client
    ...
    client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='yourdomain')
    client.ClientLogin(email='adminUsername@yourdomain', password='adminPassword', source='your-apps')
    client.UpdateSignature(username='liz', signature="Liz Jones - (+1) 619-555-5555" +
                                             "Accounts Management, A&Z LTD.")
    
  3. Here is an example of getting your Signature for your domain (thanks to this post)

    credentials = get_credentials()
    client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='yourdomain.com')
    client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
    val = client.RetrieveSignature(username="yourusername")
    

The next step is to get a list of all users for the domain and iterate over the list.

like image 63
osowskit Avatar answered Oct 20 '22 16:10

osowskit