import gdata.apps.emailsettings.client import gdata.contacts.client # replace these values with yours CONSUMER_KEY = 'mydomain.com' CONSUMER_SECRET = 'my_consumer_secret' company_name = 'ACME Inc.' admin_username = 'admin'
xoauth_requestor_id
# request a 2-legged OAuth token requestor_id = admin_username + '@' + CONSUMER_KEY two_legged_oauth_token = gdata.gauth.TwoLeggedOAuthHmacToken( CONSUMER_KEY, CONSUMER_SECRET, requestor_id) # Email Settings API client email_settings_client = gdata.apps.emailsettings.client.EmailSettingsClient( domain=CONSUMER_KEY) email_settings_client.auth_token = two_legged_oauth_token # User Profiles API client profiles_client = gdata.contacts.client.ContactsClient( domain=CONSUMER_KEY) profiles_client.auth_token = two_legged_oauth_token
HtmlSignature()
# helper class used to build signatures class SignatureBuilder(object): def HtmlSignature(self): signature = '%s' % self.name if self.occupation: signature += '%s' % self.occupation if self.company: signature += '%s' % self.company signature += 'Email: <a href=\'mailto:%s\'>%s</a> - Phone: %s' % ( self.email, self.email, self.phone_number) return signature def __init__( self, name, company='', occupation='', email='', phone_number=''): self.name = name self.company = company self.occupation = occupation self.email = email self.phone_number = phone_number
GetProfilesFeed()
next
# get all user profiles for the domain profiles = [] feed_uri = profiles_client.GetFeedUri('profiles') while feed_uri: feed = profiles_client.GetProfilesFeed(uri=feed_uri) profiles.extend(feed.entry) feed_uri = feed.FindNextLink()
SignatureBuilder
name
company
occupation
email
phone_number
# extract relevant pieces of data for each profile for entry in profiles: builder = SignatureBuilder(entry.name.full_name.text) builder.company = company_name if entry.occupation: builder.occupation = entry.occupation.text for email in entry.email: if email.primary and email.primary == 'true': builder.email = email.address for number in entry.phone_number: if number.primary and number.primary == 'true': builder.phone_number = number.text # build the signature signature = builder.HtmlSignature()
UpdateSignature
# entry.id has the following structure: # http://www.google.com/m8/feeds/profiles/domain/DOMAIN_NAME/full/USERNAME # the username is the string that follows the last / username = entry.id.text[entry.id.text.rfind('/')+1:]
# set the user's signature using the Email Settings API email_settings_client.UpdateSignature(username=username, signature=signature)
Hi Claudio!So does this mean free GApps users (gmail, custom domains) will now have the ability to set their signatures too?Thanks!/Lionel
Not really, the Email Settings API is still only available in Google Apps for Business, Education and ISPs.
Hello,A nice application would be that all email sent to be automatically signed using information from profiles.Do you think it would be possible ?
@Oliver: once you set your signature with the Email Settings API, it will be enabled and added to all outgoing emails.
There was an announcement on Google I/O about Directory API which still wasn't presented. Will it be eventually introduced?
Claudio, But there's still a 1000 chars limit for the HTML signatures?1000 chars is very little, especially if we are using tables tags, etc... in the HTML. Any plan to increase that limit?
Actually, it's 10 times bigger, maximum 10,000 characters according to Email Settings API docs.
Is there any way you can sync this with the Active Directory?
Post a Comment
10 comments :
Hi Claudio!
So does this mean free GApps users (gmail, custom domains) will now have the ability to set their signatures too?
Thanks!
/Lionel
Not really, the Email Settings API is still only available in Google Apps for Business, Education and ISPs.
Hello,
A nice application would be that all email sent to be automatically signed using information from profiles.
Do you think it would be possible ?
@Oliver: once you set your signature with the Email Settings API, it will be enabled and added to all outgoing emails.
There was an announcement on Google I/O about Directory API which still wasn't presented. Will it be eventually introduced?
There was an announcement on Google I/O about Directory API which still wasn't presented. Will it be eventually introduced?
Claudio,
But there's still a 1000 chars limit for the HTML signatures?
1000 chars is very little, especially if we are using tables tags, etc... in the HTML.
Any plan to increase that limit?
Actually, it's 10 times bigger, maximum 10,000 characters according to Email Settings API docs.
Is there any way you can sync this with the Active Directory?
Post a Comment