Skip to content

Commit

Permalink
#153 - environment variable to enable/disable email sending
Browse files Browse the repository at this point in the history
  • Loading branch information
jbc25 committed May 25, 2024
1 parent a3160d9 commit e6c0c0a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
EMAIL_USE_TLS=True
EMAIL_SEND_FROM=
ENABLE_EMAIL_SENDING=
SENTRY_DSN=
SENTRY_ENV=
2 changes: 2 additions & 0 deletions appmes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@
EMAIL_USE_TLS = env('EMAIL_USE_TLS')
EMAIL_SEND_FROM = env('EMAIL_SEND_FROM')

ENABLE_EMAIL_SENDING = env('ENABLE_EMAIL_SENDING')

# ======= Sentry Configuration ========
sentry_sdk.init(
dsn=env('SENTRY_DSN'),
Expand Down
24 changes: 14 additions & 10 deletions helpers/mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@


def send_template_email(title, destination, template_name, template_params):
msg_plain = render_to_string('email/%s.txt' % template_name, template_params)
msg_html = render_to_string('email/%s.html' % template_name, template_params)
send_mail(
title,
msg_plain,
settings.EMAIL_SEND_FROM,
[destination],
html_message=msg_html,
fail_silently=False
)

if settings.ENABLE_EMAIL_SENDING:
msg_plain = render_to_string('email/%s.txt' % template_name, template_params)
msg_html = render_to_string('email/%s.html' % template_name, template_params)
send_mail(
title,
msg_plain,
settings.EMAIL_SEND_FROM,
[destination],
html_message=msg_html,
fail_silently=False
)
else:
print("Email sending is disabled")
1 change: 1 addition & 0 deletions market/management/commands/send_test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def handle(self, *args, **options):
)

except Exception as e:
print("error")
print(e)

0 comments on commit e6c0c0a

Please sign in to comment.