From b7b8aa9a08b7e6628f0db5814ec8e822fe2e562d Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sun, 3 Oct 2021 18:38:45 -0800 Subject: [PATCH] Feature/email support (#720) * feat(frontend): :sparkles: add UI for testing email configuration * feat(backend): :sparkles: add email service with common templates (WIP) * test(backend): :white_check_mark: add basic tests for email configuration * set defaults * add email variables Co-authored-by: Hayden --- docker-compose.yml | 10 + .../documentation/getting-started/install.md | 109 ++-- docs/docs/overrides/api.html | 2 +- frontend/api/class-interfaces/email.ts | 28 + frontend/api/index.ts | 4 + .../global/BaseCardSectionTitle.vue | 12 +- frontend/pages/admin/site-settings.vue | 124 +++- frontend/static/svgs/admin-site-settings.svg | 1 + mealie/core/config.py | 29 +- mealie/routes/admin/__init__.py | 7 +- mealie/routes/admin/admin_email.py | 47 ++ mealie/services/email/__init__.py | 1 + mealie/services/email/email_senders.py | 35 ++ mealie/services/email/email_service.py | 86 +++ mealie/services/email/templates/default.html | 544 ++++++++++++++++++ poetry.lock | 99 +++- pyproject.toml | 1 + template.env | 9 +- tests/unit_tests/test_config.py | 16 + tests/unit_tests/test_email_service.py | 65 +++ 20 files changed, 1168 insertions(+), 61 deletions(-) create mode 100644 frontend/api/class-interfaces/email.ts create mode 100644 frontend/static/svgs/admin-site-settings.svg create mode 100644 mealie/routes/admin/admin_email.py create mode 100644 mealie/services/email/__init__.py create mode 100644 mealie/services/email/email_senders.py create mode 100644 mealie/services/email/email_service.py create mode 100644 mealie/services/email/templates/default.html create mode 100644 tests/unit_tests/test_email_service.py diff --git a/docker-compose.yml b/docker-compose.yml index 7674ec2937d8..1fede36bb7c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,16 @@ services: - ALLOW_SIGNUP=true - API_URL=http://mealie-api:80 + # ===================================== + # Email Configuration + # - SMTP_HOST= + # - SMTP_PORT=587 + # - SMTP_FROM_NAME=Mealie + # - SMTP_TLS=true + # - SMTP_FROM_EMAIL= + # - SMTP_USER= + # - SMTP_PASSWORD= + # ===================================== # Light Mode Config - THEME_LIGHT_PRIMARY=#E58325 diff --git a/docs/docs/documentation/getting-started/install.md b/docs/docs/documentation/getting-started/install.md index 83e69a2a26af..df533b947170 100644 --- a/docs/docs/documentation/getting-started/install.md +++ b/docs/docs/documentation/getting-started/install.md @@ -112,48 +112,79 @@ services: POSTGRES_USER: mealie ``` -## mealie-api Env Variables +## API Environment Variables -| Variables | Default | Description | -| ----------------- | :-------------------: | --------------------------------------------------------------------------------------------------------------------------------- | -| PUID | 911 | UserID permissions between host OS and container | -| PGID | 911 | GroupID permissions between host OS and container | -| DEFAULT_GROUP | Home | The default group for users | -| DEFAULT_EMAIL | changeme@email.com | The default username for the superuser | -| BASE_URL | http://localhost:8080 | Used for Notifications | -| DB_ENGINE | sqlite | Optional: 'sqlite', 'postgres' | -| POSTGRES_USER | mealie | Postgres database user | -| POSTGRES_PASSWORD | mealie | Postgres database password | -| POSTGRES_SERVER | postgres | Postgres database server address | -| POSTGRES_PORT | 5432 | Postgres database port | -| POSTGRES_DB | mealie | Postgres database name | -| TOKEN_TIME | 2 | The time in hours that a login/auth token is valid | -| API_PORT | 9000 | The port exposed by backend API. **Do not change this if you're running in Docker** | -| API_DOCS | True | Turns on/off access to the API documentation locally. | -| TZ | UTC | Must be set to get correct date/time on the server | -| WORKERS_PER_CORE | 1 | Set the number of workers to the number of CPU cores multiplied by this value (Value \* CPUs). More info [here][workers_per_core] | -| MAX_WORKERS | | Set the maximum number of workers to use. Default is not set meaning unlimited. More info [here][max_workers] | -| WEB_CONCURRENCY | 2 | Override the automatic definition of number of workers. More info [here][web_concurrency] | +### General -## mealie-frontend Env Variables +| Variables | Default | Description | +| ------------- | :-------------------: | ----------------------------------------------------------------------------------- | +| PUID | 911 | UserID permissions between host OS and container | +| PGID | 911 | GroupID permissions between host OS and container | +| DEFAULT_GROUP | Home | The default group for users | +| DEFAULT_EMAIL | changeme@email.com | The default username for the superuser | +| BASE_URL | http://localhost:8080 | Used for Notifications | +| TOKEN_TIME | 2 | The time in hours that a login/auth token is valid | +| API_PORT | 9000 | The port exposed by backend API. **Do not change this if you're running in Docker** | +| API_DOCS | True | Turns on/off access to the API documentation locally. | +| TZ | UTC | Must be set to get correct date/time on the server | -| Variables | Default | Description | -| --------------------- | :-----: | ---------------------------------- | -| ALLOW_SIGNUP | true | Allows anyone to signup for Mealie | -| THEME_LIGHT_PRIMARY | #E58325 | Light Theme Config Variable | -| THEME_LIGHT_ACCENT | #007A99 | Light Theme Config Variable | -| THEME_LIGHT_SECONDARY | #973542 | Light Theme Config Variable | -| THEME_LIGHT_SUCCESS | #43A047 | Light Theme Config Variable | -| THEME_LIGHT_INFO | #1976D2 | Light Theme Config Variable | -| THEME_LIGHT_WARNING | #FF6D00 | Light Theme Config Variable | -| THEME_LIGHT_ERROR | #EF5350 | Light Theme Config Variable | -| DARK_LIGHT_PRIMARY | #E58325 | Dark Theme Config Variable | -| DARK_LIGHT_ACCENT | #007A99 | Dark Theme Config Variable | -| DARK_LIGHT_SECONDARY | #973542 | Dark Theme Config Variable | -| DARK_LIGHT_SUCCESS | #43A047 | Dark Theme Config Variable | -| DARK_LIGHT_INFO | #1976D2 | Dark Theme Config Variable | -| DARK_LIGHT_WARNING | #FF6D00 | Dark Theme Config Variable | -| DARK_LIGHT_ERROR | #EF5350 | Dark Theme Config Variable | + +### Database + +| Variables | Default | Description | +| ----------------- | :------: | -------------------------------- | +| DB_ENGINE | sqlite | Optional: 'sqlite', 'postgres' | +| POSTGRES_USER | mealie | Postgres database user | +| POSTGRES_PASSWORD | mealie | Postgres database password | +| POSTGRES_SERVER | postgres | Postgres database server address | +| POSTGRES_PORT | 5432 | Postgres database port | +| POSTGRES_DB | mealie | Postgres database name | + +### Email + +| Variables | Default | Description | +| --------------- | :-----: | ------------------ | +| SMTP_HOST | None | Required For email | +| SMTP_PORT | 587 | Required For email | +| SMTP_FROM_NAME | Mealie | Required For email | +| SMTP_TLS | true | Required For email | +| SMTP_FROM_EMAIL | None | Required For email | +| SMTP_USER | None | Required For email | +| SMTP_PASSWORD | None | Required For email | + +### Webworkers +| Variables | Default | Description | +| ---------------- | :-----: | --------------------------------------------------------------------------------------------------------------------------------- | +| WORKERS_PER_CORE | 1 | Set the number of workers to the number of CPU cores multiplied by this value (Value \* CPUs). More info [here][workers_per_core] | +| MAX_WORKERS | | Set the maximum number of workers to use. Default is not set meaning unlimited. More info [here][max_workers] | +| WEB_CONCURRENCY | 2 | Override the automatic definition of number of workers. More info [here][web_concurrency] | + + +## Frontend Environment Variables + +### General + +| Variables | Default | Description | +| ------------ | :-----: | ---------------------------------- | +| ALLOW_SIGNUP | true | Allows anyone to signup for Mealie | + +## Themeing +| Variables | Default | Description | +| --------------------- | :-----: | --------------------------- | +| THEME_LIGHT_PRIMARY | #E58325 | Light Theme Config Variable | +| THEME_LIGHT_ACCENT | #007A99 | Light Theme Config Variable | +| THEME_LIGHT_SECONDARY | #973542 | Light Theme Config Variable | +| THEME_LIGHT_SUCCESS | #43A047 | Light Theme Config Variable | +| THEME_LIGHT_INFO | #1976D2 | Light Theme Config Variable | +| THEME_LIGHT_WARNING | #FF6D00 | Light Theme Config Variable | +| THEME_LIGHT_ERROR | #EF5350 | Light Theme Config Variable | +| DARK_LIGHT_PRIMARY | #E58325 | Dark Theme Config Variable | +| DARK_LIGHT_ACCENT | #007A99 | Dark Theme Config Variable | +| DARK_LIGHT_SECONDARY | #973542 | Dark Theme Config Variable | +| DARK_LIGHT_SUCCESS | #43A047 | Dark Theme Config Variable | +| DARK_LIGHT_INFO | #1976D2 | Dark Theme Config Variable | +| DARK_LIGHT_WARNING | #FF6D00 | Dark Theme Config Variable | +| DARK_LIGHT_ERROR | #EF5350 | Dark Theme Config Variable | ## Raspberry Pi 4 diff --git a/docs/docs/overrides/api.html b/docs/docs/overrides/api.html index 743c83c72a24..643a32de05f0 100644 --- a/docs/docs/overrides/api.html +++ b/docs/docs/overrides/api.html @@ -14,7 +14,7 @@
diff --git a/frontend/api/class-interfaces/email.ts b/frontend/api/class-interfaces/email.ts new file mode 100644 index 000000000000..e137f0cc6875 --- /dev/null +++ b/frontend/api/class-interfaces/email.ts @@ -0,0 +1,28 @@ +import { BaseAPI } from "./_base"; + +const routes = { + base: "/api/admin/email", +}; + +export interface CheckEmailResponse { + ready: boolean; +} + +export interface TestEmailResponse { + success: boolean; + error: string; +} + +export interface TestEmailPayload { + email: string; +} + +export class EmailAPI extends BaseAPI { + check() { + return this.requests.get(routes.base); + } + + test(payload: TestEmailPayload) { + return this.requests.post(routes.base, payload); + } +} diff --git a/frontend/api/index.ts b/frontend/api/index.ts index 0671b11d1a67..53e216ddc4b5 100644 --- a/frontend/api/index.ts +++ b/frontend/api/index.ts @@ -15,6 +15,7 @@ import { WebhooksAPI } from "./class-interfaces/group-webhooks"; import { AdminAboutAPI } from "./class-interfaces/admin-about"; import { RegisterAPI } from "./class-interfaces/user-registration"; import { MealPlanAPI } from "./class-interfaces/group-mealplan"; +import { EmailAPI } from "./class-interfaces/email"; import { ApiRequestInstance } from "~/types/api"; class AdminAPI { @@ -50,6 +51,7 @@ class Api { public groupWebhooks: WebhooksAPI; public register: RegisterAPI; public mealplans: MealPlanAPI; + public email: EmailAPI; // Utils public upload: UploadFile; @@ -83,6 +85,8 @@ class Api { this.upload = new UploadFile(requests); this.utils = new UtilsAPI(requests); + this.email = new EmailAPI(requests); + Object.freeze(this); Api.instance = this; } diff --git a/frontend/components/global/BaseCardSectionTitle.vue b/frontend/components/global/BaseCardSectionTitle.vue index 5ea6236f4c0e..80b24782d990 100644 --- a/frontend/components/global/BaseCardSectionTitle.vue +++ b/frontend/components/global/BaseCardSectionTitle.vue @@ -1,7 +1,11 @@