Compare commits
2 Commits
6c4b876191
...
feb4a67291
| Author | SHA1 | Date | |
|---|---|---|---|
|
feb4a67291
|
|||
|
f0b924ea56
|
@@ -76,11 +76,10 @@ class EmailService:
|
|||||||
smtp_host = self.config["smtp_host"]
|
smtp_host = self.config["smtp_host"]
|
||||||
smtp_port = self.config["smtp_port"]
|
smtp_port = self.config["smtp_port"]
|
||||||
|
|
||||||
server = smtplib.SMTP(smtp_host, smtp_port)
|
with smtplib.SMTP(smtp_host, smtp_port) as server:
|
||||||
if self.config.get("smtp_starttls", False):
|
if self.config.get("smtp_starttls", False):
|
||||||
server.starttls()
|
server.starttls()
|
||||||
|
|
||||||
try:
|
|
||||||
if self.config.get("smtp_user"):
|
if self.config.get("smtp_user"):
|
||||||
server.login(
|
server.login(
|
||||||
self.config["smtp_user"],
|
self.config["smtp_user"],
|
||||||
@@ -89,8 +88,6 @@ class EmailService:
|
|||||||
server.sendmail(msg["From"], [to], msg.as_string())
|
server.sendmail(msg["From"], [to], msg.as_string())
|
||||||
logging.info(f"Email sent: to={to} subject={subject}")
|
logging.info(f"Email sent: to={to} subject={subject}")
|
||||||
return True
|
return True
|
||||||
finally:
|
|
||||||
server.quit()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Email send failed: to={to} error={e}")
|
logging.error(f"Email send failed: to={to} error={e}")
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from peewee import (
|
|||||||
CharField,
|
CharField,
|
||||||
DateTimeField,
|
DateTimeField,
|
||||||
DoesNotExist,
|
DoesNotExist,
|
||||||
|
fn,
|
||||||
ForeignKeyField,
|
ForeignKeyField,
|
||||||
IntegerField,
|
IntegerField,
|
||||||
Model,
|
Model,
|
||||||
@@ -297,7 +298,7 @@ def get_hostname_for_user(hostname: str, user: User):
|
|||||||
Raises:
|
Raises:
|
||||||
DoesNotExist: If hostname not found or not owned by user.
|
DoesNotExist: If hostname not found or not owned by user.
|
||||||
"""
|
"""
|
||||||
fqdn = Hostname.hostname + '.' + Hostname.zone
|
fqdn = fn.Concat(Hostname.hostname, '.', Hostname.zone)
|
||||||
return Hostname.get((fqdn == hostname) & (Hostname.user == user))
|
return Hostname.get((fqdn == hostname) & (Hostname.user == user))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user