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:

  1. You have a Google Workspace (formerly G Suite) domain.
  2. You have the necessary permissions to manage your domain's settings.

Step 1: Enable the Gmail API

  1. Go to the Google Cloud Console: https://console.cloud.google.com/
  2. Select your project or create a new one.
  3. Click on "APIs & Services" and then "Dashboard".
  4. Search for "Gmail API" and click on the result.
  5. Click on the "Enable" button.

Step 2: Create a service account

  1. Go to the Google Cloud Console: https://console.cloud.google.com/
  2. Select your project or create a new one.
  3. Click on "IAM & Admin" and then "Service accounts".
  4. Click on "Create Service Account".
  5. Fill in the required information and click on "Create".
  6. Click on "Keys" and then "Add key".
  7. Select "JSON" as the key type and click on "Create".
  8. Save the JSON key file securely.

Step 3: Set up a trigger in Google Apps Script

  1. Go to the Google Apps Script editor: https://script.google.com/
  2. Create a new script by clicking on "Create" and then "Project".
  3. Name your script (e.g., "AutoSendEmail").
  4. 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

  1. Go to the Google Cloud Console: https://console.cloud.google.com/
  2. Select your project or create a new one.
  3. Click on "Cloud Scheduler" and then "Create schedule".
  4. 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)
  5. Click on "Create" to save the schedule.

Step 5: Configure the Gmail API

  1. Go to the Google Cloud Console: https://console.cloud.google.com/
  2. Select your project or create a new one.
  3. Click on "APIs & Services" and then "Dashboard".
  4. Search for "Gmail API" and click on the result.
  5. Click on the "Enable" button.
  6. 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
  7. Save the client ID and client secret securely.

Step 6: Test the setup

  1. Create a new user in your Google Workspace domain.
  2. Wait for the auto-send email to be triggered (it may take a few minutes).
  3. 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.