mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-05 00:36:18 +00:00
Build with Email enabled
This commit is contained in:
@@ -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"
|
Reference in New Issue
Block a user