Build with Email enabled

This commit is contained in:
Donald Zou
2025-01-13 16:47:15 +08:00
parent 40463d9831
commit 5d84b61f18
48 changed files with 202 additions and 59 deletions

View File

@@ -33,6 +33,7 @@ class EmailSender:
return self.DashboardConfig.GetConfig("Email", "send_from")[1]
def ready(self):
print(self.Server())
return len(self.Server()) > 0 and len(self.Port()) > 0 and len(self.Encryption()) > 0 and len(self.Username()) > 0 and len(self.Password()) > 0
def send(self, receiver, subject, body, includeAttachment = False, attachmentName = ""):
@@ -47,7 +48,7 @@ class EmailSender:
message['Subject'] = subject
message['From'] = formataddr((Header(self.SendFrom()).encode(), self.Username()))
message["To"] = receiver
message.attach(MIMEText(body, "html"))
message.attach(MIMEText(body, "plain"))
if includeAttachment and len(attachmentName) > 0:
attachmentPath = os.path.join('./attachments', attachmentName)
@@ -65,4 +66,5 @@ class EmailSender:
self.smtp.close()
return True, None
except Exception as e:
return False, f"Send failed | Reason: {e}"
return False, f"Send failed | Reason: {e}"
return False, "SMTP not configured"