Is it possible to use GAM and a template to populate user signatures?

5,530 views
Skip to first unread message

KevinMelillo

unread,
Feb 25, 2015, 4:40:21 PM2/25/15
to google-ap...@googlegroups.com
To give you some reference to what we are trying to achieve we are looking for a solution to create email signatures, but to have the unique variables such as name, phone number and email address be automatically pulled from our google user profiles so that the signatures are created and pushed automatically.  

For example this is the extent of what I know:

I have read that I can create the signature with the look and feel that I want for one user in the Gmail settings. Then run:

gam user <user email> show sig > company-sig.txt

This will download the signature and save it to company-sig.txt with the HTML formatting. Then I can run:

gam user <other user email> sig file company-sig.txt    to update the signature for another user to match.

I know you can also do:

gam all users sig file company-sig.txt  to set the signature for all users in Google Apps.

What I'm really trying to do is customize the sig per-user (name, title, dept, etc).

Is there a way I can automate this for multiple users?

Is this even possible with GAM?

Thank you for your time.

Justin Granger

unread,
Feb 25, 2015, 5:48:03 PM2/25/15
to google-ap...@googlegroups.com
I wrote a simple script to facilitate the standardization of our signatures across the company, based off of a sample script.

It pulls name, job title, email, and phone number from a TSV file HR maintains in Excel and then fills a folder with files containing each user's signature.  It also outputs a list of GAM commands to set each user's signature.

Using it take a few steps... You have to make and download one good signature as you mentioned, then split the HTML into several files named siga, sigb, etc.  These files must contain the HTML snippets between the items that change for each individual.  Then you generate the TSV file.  Now you can run the script, and then tell GAM run the out.txt batch file.  

I found that I would hit the usage limit pretty quickly even with <100 users, so I had to tell GAM not to perform simultaneous operations via the environment variable..


Please don't judge my kludged-together amateur hour code.  It did what I needed it to.  If it can help you too, enjoy!



#!/bin/bash
#setsig.sh

OIFS=$IFS
IFS=" "
x=1
while read name title phone email; do
out=`cat siga`"$name"`cat sigb`"$title"`cat sigc`"$phone"`cat sigc10`"$phone"`cat sigc20`"$email"`cat sigd`"$email"`cat sige`
echo $out  >> ./outdir/"$email"
echo "gam user $email signature file ./outdir/$email" >> out.txt 
if [ $x -gt 9 ]
then
    x=1
echo "commit-batch" >> out.txt
fi
x=$(($x+1))
echo "$x"
done < batch.tsv
IFS=""
out=`cat siga`"$name"`cat sigb`"$title"`cat sigc`"$phone"`cat sigc10`"$phone"`cat sigc20`"$email"`cat sigd`"$email"`cat sige`
echo $out  >> ./outdir/"$email"
echo "gam user $email signature file ./outdir/$email" >> out.txt 








Inline image 1 Justin Granger
Associate, Information Technology
Medullan Inc. | medullan.com
t: +1 617 547 0273
e: jgra...@medullan.com

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/013e4505-1b30-4e63-b013-cc184664c98e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

setsig.sh

Rocky Borrego

unread,
Jan 16, 2017, 5:42:08 PM1/16/17
to GAM for G Suite
Justin, thanks for the script.  I too am looking for a way to globally update all user signature files using variables for name, title, phone, etc.  However, I having a hard time maintaining a seperate CSV file with all the correct data.  

Is it possible to grab the variable info directly from the User's account at runtime?  

Ross Scroggs

unread,
Jan 16, 2017, 9:35:33 PM1/16/17
to google-ap...@googlegroups.com
Rocky,

You can't update the signature at run-time, you're got to get the data in one step and update the signature in another.


Get the data:
gam print users fields primaryemail,name,phones,organizations > Users.csv
Users.csv
primaryEmail,name.givenName,name.familyName,name.fullName,phones,organizations,organizations.0.primary,organizations.0.customType,organizations.0.title,organizations.0.type,organizations.0.department,phones.0.value,phones.0.type,organizations.0.name,phones.1.customType,phones.0.primary,phones.1.value,phones.1.type,organizations.0.description,organizations.0.costCenter,organizations.0.location,organizations.1.customType,organizations.0.symbol,organizations.1.name,organizations.0.domain

Template:
Template.txt
{First} {Last}
{RT}Title: {Title}
{/RT}Phone: {Phone}
Email: {Email}

Simplifed command syntax:
gam <UserTypeEntity> signature file <FileName> (replace <Tag> <String>)*
Every instance of {Tag} in the signature will be replaced by <String>. Instances of the form {RT}...{Tag}...{/RT} will be eliminated
if there was no <Tag> specified that matches Tag or if a <Tag> matching Tag was specified but the matching <String> is empty.
In this example, if the user doesn't have a title, the line is eliminated.

gam csv Users.csv update user "~primaryEmail" signature file Template.txt replace First "~name.givenName" replace Last "~name.familyName" replace Title "~organizations.0.title" replace Phone "~phones.0.value" replace Email "~primaryEmail"

This works but gam print users does not necessarily give you the data in an easily usable form; which phone, which title, etc? If your data is standardized, thien this might not be a problem.

Ross

On Jan 16, 2017, at 1:30 PM, Rocky Borrego <ro...@nextstepcloud.com> wrote:

Justin, thanks for the script.  I too am looking for a way to globally update all user signature files using variables for name, title, phone, etc.  However, I having a hard time maintaining a seperate CSV file with all the correct data.  

Is it possible to grab the variable info directly from the User's account at runtime?  

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.

Rocky Borrego

unread,
Jan 18, 2017, 1:01:50 PM1/18/17
to GAM for G Suite
Ross, 

Thanks so much for that info.  Doing it in two steps (first get the data, then update the signature) is a perfectly acceptable solution.  Your comments where extremely helpful and I was able to update the signatures for everyone.

One note however, for the sake of anyone else that finds themselves here, is that I had to change the command to this to be able to run...

gam csv Users.csv gam user "~primaryEmail" signature file Template.txt replace First "~name.givenName" replace Last "~name.familyName" replace Title "~organizations.0.title" replace Phone "~phones.0.value" replace Email "~primaryEmail"


Ashley Attwood

unread,
Feb 3, 2017, 6:31:57 AM2/3/17
to GAM for G Suite
Thanks again to Ross for the script. I've got the two halves working but can't get them to work in sync.

So I can write a signature out to multiple users using a CSV file and the following command:

gam csv Users.csv gam user ~primaryEmail signature "This is a signature <br> {Name}" replace Name ~name.fullName

And separately I can write out a signature based on a file:

gam user ashley.attwood signature file Template.txt

But when I put it all together:

gam csv Users.csv gam user ~primaryEmail signature file Template.txt

I get an ASCII can't decode error:

ERROR: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)


I've seen this initially when I was editing the CSV file to remove users for testing, but since using a query to filter it to just me that part seems fine. It's just now that I'm trying to use the CSV and TXT file in one command that they're not happy. Has anyone come accross this?


Thanks








This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

Ross Scroggs

unread,
Feb 3, 2017, 8:24:13 AM2/3/17
to google-ap...@googlegroups.com
Ashley,

How was Template.txt created? Are you on Windows?

gam csv Users.csv gam user ~primaryEmail signature file Template.txt replace Name ~name.fullName ...

The error has do to the fact that there are Unicode characters in Template.txt, tell gam what character set is in use.

gam csv Users.csv gam user ~primaryEmail signature file Template.txt charset utf-8 replace Name ~name.fullName ...

Try with utf-8 and utf-16 or send me the file directly and I';; figure out which it is.

Ross

--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.

Ashley Attwood

unread,
Feb 3, 2017, 9:02:14 AM2/3/17
to google-ap...@googlegroups.com
GAM (v4.11) is running on Server 2008 R2. 
Template.txt is just from notepad, saved as ANSI encoding.
Users.csv is exported directly from GAM and not touched before I call it again. 

I've tried both charsets, including re-saving my TXT file using UTF-8 encoding and that doesn't seem to help. What's really puzzling me is that the two files are perfectly happy when called separately, so I know they're compatible. Put them both in one command and it's not happy. 

Attached is the template file I'm trying to get to work right now. Just simply "Template Text" so that I know it'll work. I'll send you my user file privately.

Visit us online

Connect with us

Tweet us

{Name}
{Title}
T: {OfficePhone}
E: {Email}
W: www.aztecuk.com



To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.
To post to this group, send email to google-apps-manager@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GAM for G Suite" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/r7pyKCrluyA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-manager+unsub...@googlegroups.com.
To post to this group, send email to google-apps-manager@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Template.txt

Ashley Attwood

unread,
Feb 6, 2017, 3:51:28 AM2/6/17
to GAM for G Suite
As an update Ross picked this up with me privately and was able to replicate the problem but couldn't see exactly what was causing it. In the meantime he's pointed be towards his B version of GAM which is working like a dream.

Oscar Sironi

unread,
May 31, 2018, 3:22:28 AM5/31/18
to GAM for G Suite
Hello

This node.js script will assign the signatures stored in folders (domain.com) where the signature file name is name-surname-firma.html (firma is signature in italian) we use it in our company, since we need to update signatures very often.

If you also need to go a step further, you can use a template generator like handlebars, as we do, which will generate the signatures templates and put them in the folders mentioned above.

You can use it as a start to fit your needs, hope it helps



const DEBUG=false;
const emailFolder = ("./");
var domini = ['example.com', 'example2.com', 'example3.it' ];
const gampath = "gam";
const fs = require('fs');
const { exec } = require('child_process');
function puts(error, stdout, stderr) { sys.puts(stdout) }

try {
  domini
.forEach(dominio => {
   
if (DEBUG) console.log ("LOG: "+emailFolder+dominio);
    fs
.readdir(emailFolder+dominio, (err, files) => {
      files
.forEach(file => {
       
var useremail = file.replace(/\.html/g,'').replace(/\-/g,'.').replace(/\.firma/g,'')+"@"+dominio;
       
var command = gampath+" user "+useremail+" signature file "+emailFolder+dominio+"/"+file+" html";
       
if (!DEBUG) {
         
exec(command, (error, stdout, stderr) => {
           
if (error) {
             
throw error;
           
}
            console
.log(stdout);
         
});
       
}
       
if (DEBUG) {
          console
.log("LOG: "+command);
       
}
     
});
   
});
 
});
} catch (e) {
  console
.log(e);
}



Reply all
Reply to author
Forward
0 new messages