Added authentication option for SMTP

#893 and thank you @gdeeble!
This commit is contained in:
Donald Zou
2025-09-07 18:25:48 +08:00
parent 43d055a8b4
commit 4b713ab66e
3 changed files with 32 additions and 11 deletions

View File

@@ -73,6 +73,7 @@ class DashboardConfig:
"encryption": "",
"username": "",
"email_password": "",
"authentication_required": "true",
"send_from": "",
"email_template": ""
},

View File

@@ -31,9 +31,15 @@ class EmailSender:
def SendFrom(self):
return self.DashboardConfig.GetConfig("Email", "send_from")[1]
# Thank you, @gdeeble from GitHub
def AuthenticationRequired(self):
return self.DashboardConfig.GetConfig("Email", "authentication_required")[1]
def ready(self):
return all([self.Server(), self.Port(), self.Encryption(), self.Username(), self.Password(), self.SendFrom()])
if self.AuthenticationRequired():
return all([self.Server(), self.Port(), self.Encryption(), self.Username(), self.Password(), self.SendFrom()])
return all([self.Server(), self.Port(), self.Encryption(), self.SendFrom()])
def send(self, receiver, subject, body, includeAttachment = False, attachmentName = "") -> tuple[bool, str] | tuple[bool, None]:
if self.ready():
@@ -42,7 +48,9 @@ class EmailSender:
self.smtp.ehlo()
if self.Encryption() == "STARTTLS":
self.smtp.starttls()
self.smtp.login(self.Username(), self.Password())
if self.AuthenticationRequired():
print("Login")
self.smtp.login(self.Username(), self.Password())
message = MIMEMultipart()
message['Subject'] = subject
message['From'] = self.SendFrom()

View File

@@ -13,7 +13,7 @@ onMounted(() => {
await fetchPost("/api/updateDashboardConfigurationItem", {
section: "Email",
key: id,
value: x.value
value: store.Configuration.Email[id]
}, (res) => {
if (res.status){
x.classList.remove('is-invalid')
@@ -71,6 +71,16 @@ const sendTestEmail = async () => {
<div class="card-body d-flex flex-column gap-3">
<form @submit="(e) => e.preventDefault(e)" id="emailAccount">
<div class="row gx-2 gy-2">
<div class="col-12">
<div class="form-check mb-2 form-switch">
<input class="form-check-input" type="checkbox" role="switch"
v-model="store.Configuration.Email.authentication_required"
id="authentication_required">
<label class="form-check-label" for="authentication_required">
<LocaleText t="Require SMTP Authentication"></LocaleText>
</label>
</div>
</div>
<div class="col-12 col-lg-4">
<div class="form-group">
<label for="server" class="text-muted mb-1">
@@ -80,7 +90,7 @@ const sendTestEmail = async () => {
</label>
<input id="server"
v-model="store.Configuration.Email.server"
type="text" class="form-control">
type="text" class="form-control rounded-3">
</div>
</div>
<div class="col-12 col-lg-4">
@@ -92,7 +102,7 @@ const sendTestEmail = async () => {
</label>
<input id="port"
v-model="store.Configuration.Email.port"
type="text" class="form-control">
type="text" class="form-control rounded-3">
</div>
</div>
<div class="col-12 col-lg-4">
@@ -102,7 +112,7 @@ const sendTestEmail = async () => {
<LocaleText t="Encryption"></LocaleText>
</small></strong>
</label>
<select class="form-select"
<select class="form-select rounded-3"
v-model="store.Configuration.Email.encryption"
id="encryption">
<option value="STARTTLS">
@@ -114,7 +124,7 @@ const sendTestEmail = async () => {
</select>
</div>
</div>
<div class="col-12 col-lg-4">
<div class="col-12 col-lg-4" v-if="store.Configuration.Email.authentication_required">
<div class="form-group">
<label for="username" class="text-muted mb-1">
<strong><small>
@@ -123,10 +133,10 @@ const sendTestEmail = async () => {
</label>
<input id="username"
v-model="store.Configuration.Email.username"
type="text" class="form-control">
type="text" class="form-control rounded-3">
</div>
</div>
<div class="col-12 col-lg-4">
<div class="col-12 col-lg-4" v-if="store.Configuration.Email.authentication_required">
<div class="form-group">
<label for="email_password" class="text-muted mb-1">
<strong><small>
@@ -135,9 +145,10 @@ const sendTestEmail = async () => {
</label>
<input id="email_password"
v-model="store.Configuration.Email.email_password"
type="password" class="form-control">
type="password" class="form-control rounded-3">
</div>
</div>
<div class="col-12 col-lg-4">
<div class="form-group">
<label for="send_from" class="text-muted mb-1">
@@ -147,9 +158,10 @@ const sendTestEmail = async () => {
</label>
<input id="send_from"
v-model="store.Configuration.Email.send_from"
type="text" class="form-control">
type="text" class="form-control rounded-3">
</div>
</div>
</div>
</form>
<hr v-if="emailIsReady">