Skip to content

Commit

Permalink
feat: add from name to email closes #1726
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jan 26, 2024
1 parent b8bc559 commit fdde16c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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),
),
]
11 changes: 10 additions & 1 deletion api/tacticalrmm/core/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,6 +45,7 @@ class CoreSettings(BaseAuditModel):
smtp_from_email = models.CharField(
max_length=255, blank=True, default="[email protected]"
)
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="[email protected]"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit fdde16c

Please sign in to comment.