diff --git a/api/tacticalrmm/core/migrations/0039_coresettings_smtp_from_name.py b/api/tacticalrmm/core/migrations/0039_coresettings_smtp_from_name.py new file mode 100644 index 0000000000..70096d7097 --- /dev/null +++ b/api/tacticalrmm/core/migrations/0039_coresettings_smtp_from_name.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.9 on 2024-01-26 00:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0038_alter_coresettings_default_time_zone"), + ] + + operations = [ + migrations.AddField( + model_name="coresettings", + name="smtp_from_name", + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/api/tacticalrmm/core/models.py b/api/tacticalrmm/core/models.py index 6850506af9..73fda494ca 100644 --- a/api/tacticalrmm/core/models.py +++ b/api/tacticalrmm/core/models.py @@ -1,6 +1,7 @@ import smtplib from contextlib import suppress from email.message import EmailMessage +from email.headerregistry import Address from typing import TYPE_CHECKING, List, Optional, cast import requests @@ -44,6 +45,7 @@ class CoreSettings(BaseAuditModel): smtp_from_email = models.CharField( max_length=255, blank=True, default="from@example.com" ) + smtp_from_name = models.CharField(max_length=255, null=True, blank=True) smtp_host = models.CharField(max_length=255, blank=True, default="smtp.gmail.com") smtp_host_user = models.CharField( max_length=255, blank=True, default="admin@example.com" @@ -207,7 +209,14 @@ def send_mail( try: msg = EmailMessage() msg["Subject"] = subject - msg["From"] = from_address + + if self.smtp_from_name: + msg["From"] = Address( + display_name=self.smtp_from_name, addr_spec=from_address + ) + else: + msg["From"] = from_address + msg["To"] = email_recipients msg.set_content(body)