Skip to content

Commit

Permalink
feat(back): create email service
Browse files Browse the repository at this point in the history
  • Loading branch information
Asiberus committed Sep 20, 2022
1 parent 0679e62 commit d750f2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules
__pycache__/
*.py[cod]
*$py.class

tmp/
Empty file added back/app/services/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions back/app/services/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import threading

from django.core.mail import EmailMessage


class EmailService:
@staticmethod
def _send_mail(**kwargs):
# TODO : See to use EmailMultiAlternatives to handle both text and html email. https://docs.djangoproject.com/fr/4.1/topics/email/#sending-alternative-content-types
email = EmailMessage(**kwargs)
email.content_subtype = 'html'
email.send()

@staticmethod
def _send_mail_async(**kwargs):
threading.Thread(target=EmailService._send_mail, kwargs=kwargs).start()
4 changes: 4 additions & 0 deletions back/back/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
EXTENDED_PAGINATION_DEFAULT_SIZE = 20
EXTENDED_PAGINATION_DEFAULT_SIZE_QUERY_PARAM = 'size'

DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'tmp/email')

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

Expand Down

0 comments on commit d750f2f

Please sign in to comment.