fix: use NetBox SMTP sender address
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
+2
-1
@@ -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:
|
||||
|
||||
@@ -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"):
|
||||
|
||||
Reference in New Issue
Block a user