Autosend email on gmail when new users join in
You can set up an auto-send email on Gmail when new users join your Google Workspace (formerly G Suite) domain. Here's a step-by-step guide:
Prerequisites:
- You have a Google Workspace (formerly G Suite) domain.
- You have the necessary permissions to manage your domain's settings.
Step 1: Enable the Gmail API
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project or create a new one.
- Click on "APIs & Services" and then "Dashboard".
- Search for "Gmail API" and click on the result.
- Click on the "Enable" button.
Step 2: Create a service account
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project or create a new one.
- Click on "IAM & Admin" and then "Service accounts".
- Click on "Create Service Account".
- Fill in the required information and click on "Create".
- Click on "Keys" and then "Add key".
- Select "JSON" as the key type and click on "Create".
- Save the JSON key file securely.
Step 3: Set up a trigger in Google Apps Script
- Go to the Google Apps Script editor: https://script.google.com/
- Create a new script by clicking on "Create" and then "Project".
- Name your script (e.g., "AutoSendEmail").
- In the script editor, create a new function called
onTrigger
:function onTrigger(e) { var user = e.source.getUser(); var email = user.getEmail(); var subject = "Welcome to our domain!"; var body = "Hello " + user.getName() + ", welcome to our domain!"; MailApp.sendEmail(email, subject, body); }
This function will send an email to the new user with a welcome message.
Step 4: Set up a trigger in Google Cloud Scheduler
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project or create a new one.
- Click on "Cloud Scheduler" and then "Create schedule".
- Fill in the required information:
- Name: "AutoSendEmail"
- Description: "Send welcome email to new users"
- Frequency: "Every 1 minute" (or a suitable interval for your needs)
- Target: "Google Apps Script"
- Script: "AutoSendEmail" (the script you created earlier)
- Click on "Create" to save the schedule.
Step 5: Configure the Gmail API
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project or create a new one.
- Click on "APIs & Services" and then "Dashboard".
- Search for "Gmail API" and click on the result.
- Click on the "Enable" button.
- Go to the "OAuth 2.0 clients" page and create a new client ID:
- Authorized JavaScript origins:
https://script.google.com
- Authorized redirect URIs:
https://script.google.com
- Authorized JavaScript origins:
- Save the client ID and client secret securely.
Step 6: Test the setup
- Create a new user in your Google Workspace domain.
- Wait for the auto-send email to be triggered (it may take a few minutes).
- Verify that the email was sent successfully.
That's it! Your Gmail account should now send an auto-send email to new users who join your Google Workspace domain.