This vignette describes how
roreviewapi sends editor-search emails through the Gmail
API, sending “from” the [email protected] alias but
authorized under a single Google account. Set that account once as an
environment variable, and every later step refers back to it:
export USER_EMAIL=[email protected]This vignette complements the admin setup vignette, covering only the Gmail-specific pieces of the editor volunteer search workflow.
In the ro-auto-email project:
https://www.googleapis.com/auth/gmail.send.client_secret_<id>.apps.googleusercontent.com.json.Add [email protected] as a “Send mail as” address
under $USER_EMAIL’s Gmail settings (Settings → Accounts →
Send mail as). No separate authorization is needed, as the
gmail.send scope already covers sending as any verified
alias of that account. This is set via gm_from() on each
outgoing message.
gmail_auth() configures and authorizes
gmailr from the cached credentials.gmail_send(to, subject, html_body) builds and sends one
message via
gm_mime()/gm_from()/gm_to()/gm_subject()/gm_html_body()/
gm_send_message().gmail_send_batch(emails, links, subject, repo, issue_id)
loops gmail_send() once per recipient with
Sys.sleep(0.1) between sends, since there is no Gmail
equivalent of a batch-send endpoint for personalized messages.The send_search and handle_click endpoints
each take an injectable sender parameter (default
gmail_send_batch / gmail_send) for
testing.
| Variable | Value |
|---|---|
GMAIL_SENDER |
[email protected] |
GMAIL_OAUTH_CLIENT_SECRET |
/data/email/client_secret_<id>.apps.googleusercontent.com.json |
GMAIL_TOKEN_CACHE |
/data/email/gmailr_token |
GMAIL_AUTH_EMAIL |
$USER_EMAIL |
Set these in a local .env file for local runs. In
production they are baked into the image via Dockerfile
ENV placeholders plus a
RUN echo ... >> ~/.Renviron line — fill in the real
values directly in the Dockerfile on the droplet before
building. Do not add them to
docker-compose.yml’s environment: block: the
droplet has no .env, so ${VAR} there resolves
to an empty string and overrides the Dockerfile’s baked-in value.
Copy
client_secret_<id>.apps.googleusercontent.com.json
and the gmailr_token/ directory to
/srv/roreviewapi/data/ (bind-mounted into the container at
/data/email). That directory is Docker/root-owned, so
scp to your home directory first, then move into place:
scp client_secret_<id>.apps.googleusercontent.com.json youruser@droplet:~/
scp -r gmailr_token youruser@droplet:~/
# on the droplet:
sudo mv ~/client_secret_<id>.apps.googleusercontent.com.json /srv/roreviewapi/data/
sudo mv ~/gmailr_token /srv/roreviewapi/data/
sudo chmod 600 /srv/roreviewapi/data/client_secret_<id>.apps.googleusercontent.com.json
sudo chmod 700 /srv/roreviewapi/data/gmailr_token
sudo chmod 600 /srv/roreviewapi/data/gmailr_token/*send_search() against a real/test issue; confirm
delivery from [email protected].gmail_send().Operations only (a new person deploys/debugs, auth
stays as $USER_EMAIL) — nothing about the token
changes:
ro-auto-email Google Cloud project’s
IAM.roreviewapi GitHub repo.Authorizing identity itself (needed if
[email protected] becomes unusable, e.g. leaving the
org):
[email protected] as a “Send mail as” alias
under the new maintainer’s Gmail account.client_secret_....json, producing their own
gmailr_token/.GMAIL_AUTH_EMAIL (local .env and
Dockerfile placeholder) to their address;
GMAIL_SENDER stays
[email protected].client_secret_....json and
gmailr_token/ to /srv/roreviewapi/data/,
replacing the old ones (Section 6).restart.sh).