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

Re-add SMTP email provider #1047

Merged
merged 14 commits into from
Sep 4, 2023
Merged

Re-add SMTP email provider #1047

merged 14 commits into from
Sep 4, 2023

Conversation

sea-kelp
Copy link
Collaborator

@sea-kelp sea-kelp commented Aug 29, 2023

Description of Changes

The current EmailClient class only supports sending emails from a GSuite email account.

This change allows OpenOversight to auto-detect which email implementation to use (Google, SMTP, or Simulated) based on which of the following is configured:

  • Google: service_account_key.json file exists and is non-empty
  • SMTP: MAIL_SERVER and MAIL_PORT are set
  • Simulated: No other imeplementation is configured

Notes for Deployment

Screenshots (if appropriate)

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.

@sea-kelp
Copy link
Collaborator Author

sea-kelp commented Sep 2, 2023

@michplunkett - I just tested these changes using SMTP. Would you mind testing with a Google Workspace account?

1

@sea-kelp sea-kelp marked this pull request as ready for review September 2, 2023 03:30
Comment on lines +65 to +69
setattr(self, KEY_MAIL_SERVER, os.environ.get(KEY_MAIL_SERVER))
setattr(self, KEY_MAIL_PORT, os.environ.get(KEY_MAIL_PORT))
setattr(self, KEY_MAIL_USE_TLS, str_is_true(os.environ.get(KEY_MAIL_USE_TLS)))
setattr(self, KEY_MAIL_USERNAME, os.environ.get(KEY_MAIL_USERNAME))
setattr(self, KEY_MAIL_PASSWORD, os.environ.get(KEY_MAIL_PASSWORD))
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reasoning for using setattr instead of self.____?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, I was going back and forth about using setattr here but this lets us use the value of the constant as the config variable name, rather than hardcoding that name (for example self.MAIL_SERVER = ...) because otherwise we would need to update config.py along with constants.py if we wanted to change the config variable name.

I don't have a strong preference either way so let me know if you want me to change it

Copy link
Collaborator

Choose a reason for hiding this comment

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

The more I think about it, the more I like it. Keep it, imo. I may change the syntax for the rest of them in another PR.

@@ -13,17 +15,23 @@
class Email:
"""Base class for all emails."""

def __init__(self, body: str, subject: str, receiver: str):
def __init__(self, body: str, html: str, subject: str, receiver: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Noice.

Comment on lines 145 to +147
def str_is_true(str_):
if str_ is None:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

Comment on lines 39 to +41
ENCODING_UTF_8 = "utf-8"
FILE_TYPE_HTML = "html"
FILE_TYPE_PLAIN = "plain"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Appreciate it.

@michplunkett michplunkett self-requested a review September 2, 2023 20:53
@michplunkett
Copy link
Collaborator

Some small nits here and there, but it otherwise looks great! I'll do some testing on it Monday afternoon and stamp this bb with an 'Approved' afterward!

@classmethod
def auto_detect(cls):
"""Auto-detect the configured email provider to use for email sending."""
if current_app.testing:
Copy link
Collaborator

Choose a reason for hiding this comment

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

DEBUG is on in dev mode, so keeping DEBUG would prevent local Gmail testing.

CONTRIB.md Outdated
## Gmail Requirements
**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.
## Setting Up Email
**NOTE:** If you are running on dev and do not currently have a `service_account_key.json` file, create one and leave it empty. This file is required by docker compose.
Copy link
Collaborator

@michplunkett michplunkett Sep 4, 2023

Choose a reason for hiding this comment

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

This SHOULD be done automatically. You can remove this line because of this change: https://github.com/lucyparsons/OpenOversight/pull/1047/files#r1314475688

@@ -33,7 +33,7 @@ assets:
docker-compose run --rm web yarn build

.PHONY: dev
dev: build start create_db populate
dev: create_empty_secret build start create_db populate
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change.

@michplunkett
Copy link
Collaborator

Tested with GSuite and made the appropriate changes. Provided you're happy with it, @sea-kelp, it's good to merge!

@sea-kelp
Copy link
Collaborator Author

sea-kelp commented Sep 4, 2023

@michplunkett Thanks for the changes! Please do merge this PR when you get a chance

@michplunkett michplunkett merged commit 65a02f6 into develop Sep 4, 2023
2 checks passed
@michplunkett michplunkett deleted the add-email-providers branch September 4, 2023 18:24
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 6, 2023
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 6, 2023
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 25, 2023
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 5, 2023
AetherUnbound pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants