Skip to content

Commit 7d72518

Browse files
[ENG-11254] Improve local dev with mailhog configuration #11749
1 parent 03fabb9 commit 7d72518

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

osf/models/notification.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.utils import timezone
66

77
from api.base import settings as api_settings
8+
from website import settings as osf_settings
89
from osf import email, features
910

1011

@@ -21,7 +22,6 @@ class Notification(models.Model):
2122

2223
def send(
2324
self,
24-
protocol_type='email',
2525
destination_address=None,
2626
email_context=None,
2727
save=True,
@@ -36,22 +36,28 @@ def send(
3636
f"\ncontext={self.event_context}"
3737
f"\nemail_context={email_context}"
3838
)
39-
if protocol_type == 'email' and waffle.switch_is_active(features.ENABLE_MAILHOG):
39+
40+
if waffle.switch_is_active(features.ENABLE_MAILHOG):
4041
email.send_email_over_smtp(
4142
recipient_address,
4243
self.subscription.notification_type,
4344
self.event_context,
4445
email_context
4546
)
46-
elif protocol_type == 'email':
47+
48+
if not osf_settings.LOCAL_MODE:
4749
email.send_email_with_send_grid(
4850
recipient_address,
4951
self.subscription.notification_type,
5052
self.event_context,
5153
email_context
5254
)
53-
else:
54-
raise NotImplementedError(f'protocol `{protocol_type}` is not supported.')
55+
56+
if osf_settings.LOCAL_MODE and not waffle.switch_is_active(features.ENABLE_MAILHOG):
57+
logging.warning(
58+
'Both ENABLE_MAILHOG and LOCAL_MODE are disabled. Emails will not be sent to MailHog or real email addresses. '
59+
'Turn on ENABLE_MAILHOG to send emails to MailHog for testing, or turn on LOCAL_MODE to send emails with SendGrid.'
60+
)
5561

5662
if save:
5763
self.mark_sent()

0 commit comments

Comments
 (0)