# Connect a Google Workspace account

> Connect Google Workspace accounts with your own Internal OAuth client or an app password, and the Workspace admin settings that can block them.

Source: https://docs.posternmail.app/providers/google-workspace/

Google Workspace accounts (your own domain, hosted by Google) work like
[personal Gmail](https://docs.posternmail.app/providers/gmail/), with one advantage: if you administer the Workspace, your OAuth
client can be an **Internal** app. Internal apps need no verification, show no warning, have no
100-account limit and do not expire sign-ins after 7 days. This page covers what is different
for Workspace.

| Path | When |
|---|---|
| **Internal OAuth client** (recommended) | You are the Workspace admin, or the admin creates the client for you. |
| **App password** | Your admin allows 2-Step Verification and app passwords, and IMAP is on. |
| **External OAuth client** | The same Hub must also connect personal `@gmail.com` accounts with Google sign-in. See [Personal Gmail and Workspace on one Hub](https://docs.posternmail.app/providers/google-workspace/#personal-gmail-and-workspace-on-one-hub). |

## How Postern recognizes Workspace

When you type `you@example.com`, the Hub looks up the domain's MX records. If they point to
Google (`*.google.com` or `*.googlemail.com`), the dialog calls the provider **Google
Workspace** (for example **Connect Google Workspace**) and shows: "This domain uses Google Workspace. Sign in with Google using your own OAuth client (as
an Internal app, no verification needed), or use an app password over IMAP if your
administrator allows it."

In **Settings → Mailboxes** the mailbox is labelled **Gmail** either way.

## Option A: Internal OAuth client

### What you need

- A Workspace admin account (or an admin who does steps 1 to 3 for you).
- Your Hub opened over `https://` or on `localhost`, and `POSTERN_PUBLIC_URL` set to that
  address. See [Gmail: what you need](https://docs.posternmail.app/providers/gmail/#what-you-need-1).
- Admin rights on the Hub.

### 1. Create the project inside your organization

1. Open <https://console.cloud.google.com/> signed in with your Workspace account.
2. In the project picker click **New project**. Under **Organization** (or **Location**) choose
   your Workspace organization. Name it `Postern Hub` and click **Create**.
3. Open **APIs & Services → Library**, search for **Gmail API** and click **Enable**.

> **Check:** the project picker shows `Postern Hub` under your organization, and **Enabled APIs
> & services** lists **Gmail API**.

> **If it did not work:** if your organization does not appear, your account is not allowed to
> create projects in it. Ask a Workspace admin for the **Project Creator** role.

### 2. Configure the consent screen as Internal

1. Open **Google Auth Platform** and click **Get started** if asked.
2. **Branding:** app name `Postern Hub`, support email and developer contact.
3. **Audience:** user type **Internal**. Internal apps have no Testing or In production status
   and need no verification.
4. **Data Access → Add or remove scopes:** add `https://mail.google.com/` under **Manually add
   scopes**, then **Update** and **Save**.

> **Check:** **Audience** shows **User type: Internal**.

> **If it did not work:** **Internal** is only offered for projects inside a Workspace
> organization. Go back to step 1.

### 3. Create the client and give it to your Hub

Follow [Gmail, step 3](https://docs.posternmail.app/providers/gmail/#3-create-the-oauth-client) and
[Gmail, step 4](https://docs.posternmail.app/providers/gmail/#4-give-the-client-to-your-hub) unchanged: a **Web application** client
with the redirect URI from **Settings → Admin → Sign-in with Google and Microsoft**, then the
client ID and secret in the admin panel or in `POSTERN_GOOGLE_CLIENT_ID` and
`POSTERN_GOOGLE_CLIENT_SECRET`.

> **Check:** the admin panel shows **Google (Gmail)** as **Set up** or **Set in the Hub's
> configuration**.

> **If it did not work:** see the [Gmail troubleshooting](https://docs.posternmail.app/providers/gmail/#troubleshooting).

### 4. Allow the app in the Admin console (if your organization restricts apps)

If your organization limits which apps may access Google data, mark the client as trusted:

1. Open the Google Admin console, <https://admin.google.com/>.
2. Go to **Security → Access and data control → API controls**.
3. Click **Manage Third-Party App Access**, then **Add app → OAuth App Name Or Client ID**.
4. Search for your client ID, select it, choose who it applies to and set it to **Trusted**.

Google's help: <https://support.google.com/a/answer/7281227>.

> **Check:** the app appears in the list with access **Trusted**.

> **If it did not work:** changes in the Admin console can take a while to apply. Wait and try
> the sign-in again.

### 5. Add the mailbox

**Settings → Mailboxes → Add mailbox**, pick **Google**, type your work address and click
**Sign in with Google**. Internal apps show no "unverified" warning. Allow access and you are
back in Postern.

> **Check:** **Settings → Mailboxes** shows the address with **Downloading mail, …% done**.

> **If it did not work:** see [Troubleshooting](https://docs.posternmail.app/providers/google-workspace/#troubleshooting).

## Option B: App password

### 1. Make sure your admin allows it

In the Google Admin console:

- **Security → Authentication → 2-step verification**: **Allow users to turn on 2-Step
  Verification** must be on. Organizations that enforce security keys only may hide app
  passwords.
- **Apps → Google Workspace → Gmail → End User Access**: **POP and IMAP access** must be
  enabled for your users. Google's help: <https://support.google.com/a/answer/105694>.

> **Check:** you can open <https://myaccount.google.com/apppasswords> with your work account.

> **If it did not work:** "The setting you are looking for is not available for your account"
> means app passwords are not allowed for you. Use Option A.

### 2. Create the app password and add the mailbox

Follow [Gmail, Option A](https://docs.posternmail.app/providers/gmail/#option-a-app-password) from step 1. In the dialog, pick
**Other** and type your work address so you can choose **Use a password** (picking **Google**
goes straight to Google sign-in when the Hub has it).

| | Server | Port | Security |
|---|---|---|---|
| Incoming (IMAP) | `imap.gmail.com` | 993 | TLS |
| Outgoing (SMTP) | `smtp.gmail.com` | 465 | TLS |
| Username | your full work address | | |

> **Check:** the mailbox shows **Gmail · Downloading mail, …% done**.

> **If it did not work:** **The sign-in was rejected** usually means IMAP access is off for
> your account or the app password is wrong.

## What the Hub does with Workspace

The same as with [Gmail](https://docs.posternmail.app/providers/gmail/#what-the-hub-does-with-gmail). One difference matters more in
organizations: with Google sign-in, the Hub uses an IMAP connection to `imap.gmail.com` to learn
about new mail quickly. If your admin turned IMAP off, sign-in still works and the Hub checks
for changes every 10 seconds through the Gmail API instead.

Aliases of your Workspace account (for example `sales@example.com`) can be added under
**Settings → Identities & signatures**. Gmail must also know them as **Send mail as** addresses,
or it sends with your main address.

## Personal Gmail and Workspace on one Hub

A Hub has **one** Google OAuth client. An Internal client only accepts accounts from its own
organization, so personal `@gmail.com` accounts cannot use it. Choose one of:

- the Internal client for Workspace accounts, and **app passwords** for personal Gmail, or
- an **External, In production** client for everyone. The 100-account limit and the
  "unverified app" warning then apply to the Workspace accounts too
  (see [Gmail limits](https://docs.posternmail.app/providers/gmail/#limits)).

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Google shows **Error 403: org_internal** | You signed in with an account outside the client's organization. | Use an account of that organization, or an External client. |
| Google shows **This app is blocked** or **admin_policy_enforced** | Your organization restricts third-party apps. | Step 4: mark the client as **Trusted**. |
| App passwords page not available | App passwords are off for you, or 2-Step Verification is off. | Ask your admin, or use Option A. |
| **The sign-in was rejected** with an app password | IMAP is off for your account, or the password is wrong. | Check **POP and IMAP access** in the Admin console; create a new app password. |
| Mail arrives with a delay of a few seconds | IMAP is off, so the Hub checks every 10 seconds instead of waiting for IMAP's notice. | Nothing to do, or turn IMAP on for the account. |

More messages and their fixes are in the [Gmail troubleshooting](https://docs.posternmail.app/providers/gmail/#troubleshooting).
