Skip to content

Commit 6306a70

Browse files
author
Adrian Berger
committed
feat: add name as part of sender
1 parent 769c67c commit 6306a70

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

django_mailomat/backend.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ def _sanitize_email(self, email: str) -> str:
2727
return email.split('<')[1].split('>')[0]
2828
return email
2929

30-
def _format_email(self, email: str, name: Optional[str] = None) -> str:
30+
def _format_email(self, email: str, name: Optional[str] = None) -> dict:
3131
"""
3232
Format email address with optional display name.
33+
Returns a dictionary with email and name fields.
34+
If no name is provided, uses the email address as the name.
3335
"""
34-
if name:
35-
return formataddr((name, self._sanitize_email(email)))
36-
return self._sanitize_email(email)
36+
sanitized_email = self._sanitize_email(email)
37+
return {
38+
'email': sanitized_email,
39+
'name': name if name else sanitized_email
40+
}
3741

3842
def _send(self, email_message: Union[EmailMessage, EmailMultiAlternatives]) -> bool:
3943
"""

0 commit comments

Comments
 (0)