diff --git a/CHANGELOG.md b/CHANGELOG.md index 703c00f..2241708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Make the required single platform destination explicit when creating an installation * Fix installation form submission on NetBox v4.6.5 when form mixins return no cleaned-data value * Prevent the notification log creation flag from shadowing Django's translation function during email delivery +* Use NetBox's configured `EMAIL['FROM_EMAIL']` value as the SMTP sender instead of Django's localhost fallback ### Added diff --git a/netbox_slm/__init__.py b/netbox_slm/__init__.py index 768d451..fff3279 100644 --- a/netbox_slm/__init__.py +++ b/netbox_slm/__init__.py @@ -17,7 +17,7 @@ limitations under the License. from netbox.plugins import PluginConfig from django.utils.translation import gettext_lazy as _ -__version__ = "1.12.2" +__version__ = "1.12.3" class SLMConfig(PluginConfig): diff --git a/netbox_slm/jobs.py b/netbox_slm/jobs.py index 940b1e9..051da6e 100644 --- a/netbox_slm/jobs.py +++ b/netbox_slm/jobs.py @@ -81,7 +81,8 @@ class LicenseExpirationNotificationJob(JobRunner): body += "\n" + _("Provider portal: %(url)s") % {"url": license.provider_portal_url} try: - send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False) + from_email = settings.SERVER_EMAIL or settings.EMAIL_HOST_USER + send_mail(subject, body, from_email, [user.email], fail_silently=False) except Exception: self.logger.exception(f"Failed to send expiration email for license {license.pk} to user {user}") else: diff --git a/netbox_slm/tests/test_models.py b/netbox_slm/tests/test_models.py index fb74949..67fd015 100644 --- a/netbox_slm/tests/test_models.py +++ b/netbox_slm/tests/test_models.py @@ -4,6 +4,7 @@ from unittest.mock import Mock, patch from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError +from django.test import override_settings from django.utils import timezone from django.utils.translation import gettext, override from extras.models import Notification, Subscription @@ -161,6 +162,7 @@ class ModelTestCase(SlmBaseTestCase): license.get_notification_dates(), ) + @override_settings(SERVER_EMAIL="netbox@example.com", EMAIL_HOST_USER="smtp-user") @patch("netbox_slm.jobs.send_mail") def test_expiration_job_notifies_subscribers_once(self, send_mail): user = get_user_model().objects.create_user( @@ -190,6 +192,7 @@ class ModelTestCase(SlmBaseTestCase): self.assertEqual(1, Notification.objects.filter(user=user, object_id=license.pk).count()) self.assertEqual(1, SoftwareLicenseNotificationLog.objects.filter(user=user, license=license).count()) send_mail.assert_called_once() + self.assertEqual("netbox@example.com", send_mail.call_args.args[2]) def test_german_translation(self): with override("de"):