Skip to content

Commit

Permalink
feat(mailing): enabled smtp mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 21, 2023
1 parent 6b3bfeb commit 37f987b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ jobs:
sentry:
dsn: ${{ secrets.SENTRY_DSN }}
jsLoaderUrl: ${{ secrets.SENTRY_JS_LOADER_URL }}
mailer:
primary:
host: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST }}
port: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST_PORT }}
user: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST_USER }}
password: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST_PASSWORD }}
value-files: >-
[
"charts/values.yaml"
Expand Down
6 changes: 6 additions & 0 deletions charts/templates/web-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
"DJANGO_AWS_S3_SECRET_ACCESS_KEY" (.Values.secrets.s3.accessKey | b64enc)
"DJANGO_AWS_S3_REGION_NAME" (.Values.secrets.s3.regionName | b64enc)
"DJANGO_AWS_STORAGE_BUCKET_NAME" (.Values.secrets.s3.bucketName | b64enc)

"DJANGO_SENTRY_DSN" (.Values.secrets.sentry.dsn | b64enc)
"DJANGO_SENTRY_JS_LOADER_URL" (.Values.secrets.sentry.jsLoaderUrl | b64enc)

"DJANGO_MAILER_PRIMARY_HOST" (.Values.secrets.mailer.primary.host | b64enc)
"DJANGO_MAILER_PRIMARY_HOST_PORT" (.Values.secrets.mailer.primary.port | b64enc)
"DJANGO_MAILER_PRIMARY_HOST_USER" (.Values.secrets.mailer.primary.user | b64enc)
"DJANGO_MAILER_PRIMARY_HOST_PASSWORD" (.Values.secrets.mailer.primary.password | b64enc)
)
}}
{{- include "fiesta.secret" (merge (dict "Args" $data) . ) -}}
6 changes: 6 additions & 0 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ secrets:
sentry:
dsn: dsn
jsLoaderUrl: url
mailer:
primary:
host: host
port: 587
user: user
password: password
8 changes: 7 additions & 1 deletion fiesta/fiesta/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .db import DatabaseConfigMixin
from .files import FilesConfigMixin, S3ConfigMixin
from .logging import LoggingConfigMixin, SentryConfigMixin
from .notifications import SmtpMailerConfigMixin
from .project import ProjectConfigMixin
from .security import SecurityConfigMixin
from .templates import TemplatesConfigMixin
Expand Down Expand Up @@ -55,7 +56,12 @@ class LocalProduction(Base):
USE_WEBPACK_INTEGRITY = False


class Production(S3ConfigMixin, SentryConfigMixin, Base):
class Production(
SmtpMailerConfigMixin,
S3ConfigMixin,
SentryConfigMixin,
Base,
):
DEBUG = False

ROOT_DOMAIN = Value(environ_required=True)
Expand Down
38 changes: 38 additions & 0 deletions fiesta/fiesta/settings/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

from configurations.values import SecretValue, Value

from ._utils import BaseConfigurationProtocol


class SmtpMailerConfigMixin(BaseConfigurationProtocol):
MAILER_PRIMARY_BACKEND = Value(default="django.core.mail.backends.smtp.EmailBackend")
MAILER_PRIMARY_TIMEOUT = Value(default=5)
MAILER_PRIMARY_HOST = SecretValue()
MAILER_PRIMARY_HOST_PORT = SecretValue()
MAILER_PRIMARY_HOST_PASSWORD = SecretValue()
MAILER_PRIMARY_HOST_USER = SecretValue()

@property
def EMAIL_BACKEND(self):
return self.MAILER_PRIMARY_BACKEND

@property
def EMAIL_TIMEOUT(self):
return self.MAILER_PRIMARY_TIMEOUT

@property
def EMAIL_HOST(self):
return self.MAILER_PRIMARY_HOST

@property
def EMAIL_PORT(self):
return self.MAILER_PRIMARY_HOST_PORT

@property
def EMAIL_HOST_USER(self):
return self.MAILER_PRIMARY_HOST_USER

@property
def EMAIL_HOST_PASSWORD(self):
return self.MAILER_PRIMARY_HOST_PASSWORD
4 changes: 4 additions & 0 deletions fiesta/fiesta/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class ProjectConfigMixin:
def ALLOWED_HOSTS(self):
return [f".{self.ROOT_DOMAIN}"]

# overwritten by production mixins
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

def DEFAULT_FROM_EMAIL(self):
return f"Fiesta+ <noreply@{self.ROOT_DOMAIN}>"

INSTALLED_APPS = [
# dj admin autocompletion widgets, must be before admin
"dal",
Expand Down

0 comments on commit 37f987b

Please sign in to comment.