Ensure that all your users have a standard signature by updating them using the gmail API. Users signatures can be updated direct from the GSuite users directory using standard and custom fields or alternatively from a JSON users file.
- defaultSig.html template is included, you can add your own templates to the "signatures" directory.
- testUsers.json JSON file is included as an example when fetching users from local source rather than GSuite domain.
- Fetch users direct from GSuite directory including all attributes (Full name, phone number, profile photo, etc...).
- Support for auto fetching and mapping of GSuite directory custom attributes to merge tags for use in email signatures.
- You are a GSuite domain admin with full super admin access
- Make sure your are running at least PHP 5.4+
- Your PHP server can read files from the local_vars and signatures directory (after installing)
Ensure that you have gone through the steps described here to get your service-account.json file. More information can be found on the Google Admin SDK Guide to setting up a service account for your GSuite domain.
Copy your service-account.json file into the local_vars directory
Ensure that you have granted domain wide delegation through the GSuite console for the following scopes of your service account
https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.alias', 'https://www.googleapis.com/auth/admin.directory.userschema','https://www.googleapis.com/auth/gmail.settings.basic','https://www.googleapis.com/auth/gmail.settings.sharing
composer require moometric/gsuite
OR
git clone https://github.com/moometric/GSuiteSignatureManager.git
By default there is a signature template located in "signatures/defaultSig.html". You can modify this template and include your own MERGE fields.
Merge fields are in the following format {{mergeFieldOne}}. If you're not sure what merge fields you can use, use listMergeFields() function to view a list of available merge tags.
If using composer, don't forget to include your autoload file.
require_once '/path/to/your-project/vendor/autoload.php';
use Moometric\mooSignature;
$mooSig = new mooSignature("primaryDomain.com", "adminEmail@primaryDomain.com");
// Optionally set the path where your default service-account.json file is stored.
$mooSig->addSettingServiceAccountPath("/your/project/path/local_vars/");
// Optionally set the path where your signatures are stored.
$mooSig->addsettingSignaturePath("/your/project/path/signatures/");
Included is an index.php file which contains a few tests to get started.
Once you go live, ensure that you switch off testing mode.
$mooSig->addSettingRunTestMode(False);
This will set "Hello World" as the MOTD for all GSuite users
$mooSig->addSettingMOTDHTML("<span style=\"color: red;\">Hello World</span>");
$mooSig->addSettingMOTDPosition("Below");
$mooSig->addSettingMOTD(True);
$mooSig->setSignatureMOTD();
If exists, this will remove MOTD for all GSuite users
$mooSig->removeSignatureMOTD();
If you only want certain GSuite users to have a MOTD, you can filter the users by their primary email.
$mooSig->addSettingMOTDHTML("<span style=\"color: red;\">Marketing Department MOTD</span>");
$mooSig->addSettingFilterEmailsToUpdate(["fakeEmail@moometric.com", "anotherEmail@moometric.com"]);
$mooSig->setSignatureMOTD();
Or remove MOTD from those same select users
$mooSig->removeSignatureMOTD();
Update the signature for all domain users from the default template.
$mooSig->addSettingSetTemplate("defaultSig.html");
$mooSig->updateSignatures();
Update the signature for all domain users from the default template.
$mooSig->addSettingMOTDHTML("<span style=\"color: red;\">Hello World</span>");
$mooSig->updateSignatures();
Update the signature for all domain users from the default template. In the example below only fakeEmail@moometric.com and anotherEmail@moometric.com will be updated, all other users will be excluded
$mooSig->addSettingFilterEmailsToUpdate(["fakeEmail@moometric.com", "anotherEmail@moometric.com"]);
$mooSig->updateSignatures();
Update the signature for all domain users but exclude those who don't have a profile photo or title set.
$mooSig->addSettingSkipConditions(["title", "thumbnailPhotoUrl"]);
$mooSig->updateSignatures();
Update the signature for users in the JSON file testUsers.json.
$mooSig->addSettingUsersFile("testUsers.json");
$mooSig->updateSignatures();
In this example only users who are in the array below will be updated with a new signature. Two users below will be updated.
$mooSig->addSettingUserArray([
[
"primaryEmail" => "fakeEmail@moometric.com",
"alias" => "fakeEmail@moometric.com",
"fullName" => "MooMaster",
],
[
"primaryEmail" => "anotherEmail@moometric.com",
"alias" => "anotherEmail@moometric.com",
"fullName" => "MooMinor",
]
]);
$mooSig->updateSignatures();
If you want to see what merge fields are available for use in your template, you can run the following function to echo and output to your browser.
$mooSig->listMergeFields();
Output will look something like this
Merge Tag | Example |
---|---|
{{primaryEmail}} | fakeEmail@moometric.com |
{{alias}} | fakeEmail@moometric.com |
{{thumbnailPhotoUrl}} | http://i.imgur.com/mmvUt5x.png |
{{fullName}} | MooMaster |
{{phone0}} | 555-555-555 |
{{title}} | IT Admin / Developer |
If your signature, service-account.json or user defined JSON file aren't stored in the default directories, you can use the following to set the path where your files are located.
Set the directory where your service-account.json file is stored
$mooSig->addSettingServiceAccountPath("/your/project/path/local_vars/");
Set the directory where your signatures are stored
$mooSig->addsettingSignaturePath("/your/project/path/signatures/");
Set the directory where your users json files are stored. This is only required if you are fetching your users from a local JSON file, rather than the GSuite directory.
$mooSig->addSettingJSONPath("/your/project/path/local_vars/");
During test mode no signatures are updated
$mooSig->addSettingRunTestMode(True);
When testing, echo the signature into your browser
$mooSig->addSettingPreviewSignature(True);
Rather than JSON or other array. Default is True. Will default to False if you use specify a JSON array or another array source after this flag has been set.
$mooSig->addSettingGetUsersFromGsuite(True);
you wish to use that is located in the subfolder "/signatures"
mooSig->addSettingSetTemplate("defaultSig.html");
that start and end with '{{' '}}' when generating the template. Switch to False when debugging.
$mooSig->addSettingStripBlanks(True);
Skip updates if any of the fields are NULL, BLANK or don't exist. Useful when updating users that might have blank values that need to be updated before their signature is created. In the example below, we're skipping the signature update for users that don't have their title or profile picture set.
$mooSig->addSettingSkipConditions(["title", "thumbnailPhotoUrl"]);
Enter the primaryEmail addresses that you wish you update. Any emails that aren't included here won't be updated.
$mooSig->addSettingFilterEmailsToUpdate(["fakeEmail@moometric.com", "anotherEmail@moometric.com"]);
If filters have been applied, you can unset them all using the following. Useful if you're chaining a whole heap of bulk updates with many different changing filters
$mooSig->addSettingUnsetFilters();
Set where the MOTD appears (Above or Below) on the signature.
$mooSig->addSettingMOTDPosition("Below");
String value of the HTML that you want to include in the email signature.
$mooSig->addSettingMOTDHTML("<span style=\"color: red;\">Hello World</span>");
If you don't set the MOTD HTML, this will have no effect. Otherwise when the template for a user is generated, the MOTD will be included upon generation.
$mooSig->addSettingMOTD(True);
If you would prefer to get the users details from an array rather than the GSuite directory, you can push your own custom users array along with all the details for the signatures you wish to update. For this option you must include the primaryEmail and alias in each user array.
$mooSig->addSettingUserArray([
[
"primaryEmail" => "fakeEmail@moometric.com",
"alias" => "fakeEmail@moometric.com",
"thumbnailPhotoUrl" => "http://i.imgur.com/mmvUt5x.png",
"fullName" => "MooMaster",
"phone0" => "555-555-555",
"title" => "IT Admin / Developer"
],
[
"primaryEmail" => "anotherEmail@moometric.com",
"alias" => "anotherEmail@moometric.com",
"thumbnailPhotoUrl" => "http://i.imgur.com/mmvUt5x.png",
"fullName" => "MooMinor",
"phone0" => "444-444-444",
"title" => "DevOps Admin"
]
]);
If you would prefer to get the users details from a JSON file rather than the GSuite directory, you can add your JSON file to the /local_vars folder instead. For this option you must include the primaryEmail and alias in each JSON object.
$mooSig->addSettingUsersFile("testUsers.json");
Example JSON File
[
{
"primaryEmail": "fakeEmail@moometric.com",
"alias": "fakeEmail@moometric.com",
"thumbnailPhotoUrl": "http://i.imgur.com/mmvUt5x.png",
"fullName": "MooMaster",
"phone0": "555-555-555",
"title": "IT Admin / Developer"
},
{
"primaryEmail": "anotherEmail@moometric.com",
"alias": "anotherEmail@moometric.com",
"thumbnailPhotoUrl": "http://i.imgur.com/mmvUt5x.png",
"fullName": "MooMinor",
"phone0": "444-444-444",
"title": "DevOps Admin"
}
]
- MooMaster - initial work - Moometric.com
This project is licensed under the MIT License - see the LICENSE.md file for details