Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gmail client and update email functions #944

Merged
merged 123 commits into from
Jul 7, 2023
Merged

Conversation

michplunkett
Copy link
Collaborator

@michplunkett michplunkett commented Jun 27, 2023

Fixes issue

#927

Description of Changes

Add the ability to send emails from a Google Workspace account using a GCP service account and update the feature's respective documentation.

Notes for Deployment

  • Need service_account_key.json file that is stored in LPL document storage.

Email Screenshots

Administrator Approval Email:

Confirm Account Email:

Screenshot 2023-07-05 at 9 36 09 PM

Change Email Address Email:

Screenshot 2023-07-05 at 9 40 03 PM

Confirmed User Email:

Screenshot 2023-07-05 at 9 43 44 PM

Reset Password Email:

Screenshot 2023-07-05 at 9 45 04 PM

Tests and linting

  • This branch is up-to-date with the develop branch.
  • pytest passes on my local development environment.
  • pre-commit passes on my local development environment.

@michplunkett michplunkett self-assigned this Jun 27, 2023
.gitignore Outdated Show resolved Hide resolved
@michplunkett michplunkett changed the title Add service account email client Add Google email client Jun 27, 2023
@michplunkett michplunkett changed the title Add Google email client Add Google email client and update email commands Jun 28, 2023
subject = (
f"{current_app.config.get('OO_MAIL_SUBJECT_PREFIX')} Reset Your Password"
)
body = render_template("auth/email/reset_password.html", user=user, token=token)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +53 to +67
**NOTE:** If you are running on dev and do not currently have a `service_account_key.json` file, create one and leave it empty. The email client will then default to an empty object and simulate emails in the logs.

For the application to work properly, you will need a [Google Cloud Platform service account](https://cloud.google.com/iam/docs/service-account-overview) that is attached to a GSuite email address. Here are some general tips for working with service accounts: [Link](https://support.google.com/a/answer/7378726?hl=en).
We would suggest that you do not use a personal email address, but instead one that is used strictly for sending out OpenOversight emails.

You will need to do these two things for the service account to work as a Gmail bot:
1. Enable domain-wide delegation for the service account: [Link](https://support.google.com/a/answer/162106?hl=en)
2. Enable the `https://www.googleapis.com/auth/gmail.send` scope in the Gmail API for your service account: [Link](https://developers.google.com/gmail/api/auth/scopes#scopes)
3. Save the service account key file in OpenOversight's base folder as `service_account_key.json`. The file is in the `.gitignore` file GitHub will not allow you to save it, provided you've named it correctly.
4. For production, save the email address associated with your service account to a variable named `OO_SERVICE_EMAIL` in a `.env` file in the base directory of this repository. For development and testing, update the `OO_SERVICE_EMAIL` variable in the `docker-compose.yml` file.

Example `.env` variable:
```bash
OO_SERVICE_EMAIL="[email protected]"
```
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be all of the info needed, @abandoned-prototype.

Copy link
Collaborator

@abandoned-prototype abandoned-prototype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all my suggestions. This looks great now!
I realized that I don't seem to have access to the required service_account_key.json file, so I will merge this tomorrow after setting that file up correctly on staging

@michplunkett michplunkett changed the title Add Google email client and update email commands Add Gmail client and update email functions Jul 7, 2023
@abandoned-prototype abandoned-prototype merged commit c964a94 into develop Jul 7, 2023
@abandoned-prototype abandoned-prototype deleted the email_issue branch July 7, 2023 02:53
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 6, 2023
lucyparsons#927

Add the ability to send emails from a Google Workspace account using a
GCP service account and update the feature's respective documentation.

- Need `service_account_key.json` file that is stored in LPL document
storage.

---------

Co-authored-by: abandoned-prototype <[email protected]>
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 25, 2023
lucyparsons#927

Add the ability to send emails from a Google Workspace account using a
GCP service account and update the feature's respective documentation.

- Need `service_account_key.json` file that is stored in LPL document
storage.

---------

Co-authored-by: abandoned-prototype <[email protected]>
sea-kelp pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 5, 2023
lucyparsons#927

Add the ability to send emails from a Google Workspace account using a
GCP service account and update the feature's respective documentation.

- Need `service_account_key.json` file that is stored in LPL document
storage.

---------

Co-authored-by: abandoned-prototype <[email protected]>
AetherUnbound pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 9, 2023
lucyparsons#927

Add the ability to send emails from a Google Workspace account using a
GCP service account and update the feature's respective documentation.

- Need `service_account_key.json` file that is stored in LPL document
storage.

---------

Co-authored-by: abandoned-prototype <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants