-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add from name to email closes #1726
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
api/tacticalrmm/core/migrations/0039_coresettings_smtp_from_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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]" | ||
|
@@ -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) | ||
|
||
|