mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-28 01:17:21 +00:00
Offfload email notification (#12470)
* Offfload email notification * Run email sync in testing
This commit is contained in:
@@ -69,8 +69,21 @@ def send_email(
|
|||||||
html_message=None,
|
html_message=None,
|
||||||
prio: Priority = Priority.NORMAL,
|
prio: Priority = Priority.NORMAL,
|
||||||
headers: Optional[dict] = None,
|
headers: Optional[dict] = None,
|
||||||
|
force_async: bool = False,
|
||||||
|
**kwargs,
|
||||||
) -> tuple[bool, Optional[str]]:
|
) -> 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):
|
if isinstance(recipients, str):
|
||||||
recipients = [recipients]
|
recipients = [recipients]
|
||||||
|
|
||||||
@@ -109,6 +122,7 @@ def send_email(
|
|||||||
html_message=html_message,
|
html_message=html_message,
|
||||||
prio=prio,
|
prio=prio,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
force_async=force_async,
|
||||||
group='notification',
|
group='notification',
|
||||||
)
|
)
|
||||||
return True, None
|
return True, None
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Core set of Notifications as a Plugin."""
|
"""Core set of Notifications as a Plugin."""
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
@@ -109,7 +110,11 @@ class InvenTreeEmailNotifications(NotificationMixin, SettingsMixin, InvenTreePlu
|
|||||||
|
|
||||||
if recipients:
|
if recipients:
|
||||||
InvenTree.helpers_email.send_email(
|
InvenTree.helpers_email.send_email(
|
||||||
subject, '', recipients, html_message=html_message
|
subject,
|
||||||
|
'',
|
||||||
|
recipients,
|
||||||
|
html_message=html_message,
|
||||||
|
force_async=not settings.TESTING,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ class CoreNotificationTestTests(InvenTreeTestCase):
|
|||||||
# No email should be send
|
# No email should be send
|
||||||
self.assertEqual(len(mail.outbox), 0)
|
self.assertEqual(len(mail.outbox), 0)
|
||||||
|
|
||||||
print('- get email plugin:')
|
|
||||||
|
|
||||||
plugin = registry.get_plugin('inventree-email-notification')
|
plugin = registry.get_plugin('inventree-email-notification')
|
||||||
self.assertIsNotNone(plugin, 'Email notification plugin should be available')
|
self.assertIsNotNone(plugin, 'Email notification plugin should be available')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user