Add support for fromName, update README
All checks were successful
/ test (push) Successful in 5s

This commit is contained in:
phil 2024-12-03 18:32:59 +01:00
parent 6d8743e183
commit f6d0916dec
4 changed files with 69 additions and 19 deletions

View file

@ -31,7 +31,7 @@ class MailSettings(BaseSettings):
"""\
{text}
---
From: {from}
From: {from} {fromName}
Sent: {sentStamp:%c}
Received: {receivedStamp:%c}
Sim: {sim}
@ -45,7 +45,8 @@ class Settings(BaseSettings):
class SmsAlert(BaseModel):
from_: str = Field(alias="from")
from_: str = Field(alias="from") # "from" is reserved word in Python, use an alias
fromName: str = ""
text: str
sentStamp: datetime
receivedStamp: datetime
@ -61,7 +62,7 @@ def send_mail(smsAlert: SmsAlert):
msg["Subject"] = f"SMS from {smsAlert.from_}"
msg["From"] = settings.mail.sender
msg["To"] = settings.mail.to
fmt = dict(smsAlert)
fmt = dict(smsAlert) # Make a dict for sms
fmt["from"] = fmt.pop("from_")
msg.set_content(settings.mail.template.format_map(fmt))
return send(