diff --git a/src/backend/InvenTree/InvenTree/helpers_email.py b/src/backend/InvenTree/InvenTree/helpers_email.py index f6dca007f2..6a0894b73a 100644 --- a/src/backend/InvenTree/InvenTree/helpers_email.py +++ b/src/backend/InvenTree/InvenTree/helpers_email.py @@ -69,8 +69,21 @@ def send_email( html_message=None, prio: Priority = Priority.NORMAL, headers: Optional[dict] = None, + force_async: bool = False, + **kwargs, ) -> tuple[bool, Optional[str]]: - """Send an email with the specified subject and body, to the specified recipients list.""" + """Send an email with the specified subject and body, to the specified recipients list. + + Arguments: + subject: Subject of the email + body: Body of the email + recipients: List of recipients (or a single recipient) + from_email: Optional sender email address (if not specified, will use DEFAULT_FROM_EMAIL) + html_message: Optional HTML message to send + prio: Priority of the email (default is normal) + headers: Optional dictionary of headers to include in the email + force_async: If True, will force the email to be sent asynchronously + """ if isinstance(recipients, str): recipients = [recipients] @@ -109,6 +122,7 @@ def send_email( html_message=html_message, prio=prio, headers=headers, + force_async=force_async, group='notification', ) return True, None diff --git a/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py b/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py index 6d9e8a5099..0b732bcb64 100644 --- a/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py +++ b/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py @@ -1,5 +1,6 @@ """Core set of Notifications as a Plugin.""" +from django.conf import settings from django.contrib.auth.models import User from django.db.models import Model from django.template.loader import render_to_string @@ -109,7 +110,11 @@ class InvenTreeEmailNotifications(NotificationMixin, SettingsMixin, InvenTreePlu if recipients: InvenTree.helpers_email.send_email( - subject, '', recipients, html_message=html_message + subject, + '', + recipients, + html_message=html_message, + force_async=not settings.TESTING, ) return True diff --git a/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py b/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py index fbff6bc894..bddb848745 100644 --- a/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py +++ b/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py @@ -44,8 +44,6 @@ class CoreNotificationTestTests(InvenTreeTestCase): # No email should be send self.assertEqual(len(mail.outbox), 0) - print('- get email plugin:') - plugin = registry.get_plugin('inventree-email-notification') self.assertIsNotNone(plugin, 'Email notification plugin should be available')