Skip to content

Commit

Permalink
fixes issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalec committed May 31, 2021
1 parent cc6633c commit 17d7f49
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
deemon.egg-info
dist
venv
deemon/app/.cache
32 changes: 16 additions & 16 deletions deemon/app/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ class EmailNotification:

def __init__(self, config):
self.config = config
self.enable_notify = True if self.config["smtp_server"] else False
self.enable_notify = True if self.config["smtp_server"] != "" else False

def notify(self, new_releases=[], test=False):
if test:
message = "Congrats! You'll now receive new release notifications."
subject = "deemon Test Notification"
else:
elif self.enable_notify:
message = "The following new releases were detected:\n"
subject = "New release(s) detected!"
for release in new_releases:
message = message + "\n" + release
msg = EmailMessage()
msg['From'] = formataddr(('deemon', self.config["smtp_sender_email"]))
msg['Subject'] = subject
msg['To'] = self.config["smtp_recipient"]
msg.set_content(message)
msg = EmailMessage()
msg['From'] = formataddr(('deemon', self.config["smtp_sender_email"]))
msg['Subject'] = subject
msg['To'] = self.config["smtp_recipient"]
msg.set_content(message)

context = ssl.create_default_context()
context = ssl.create_default_context()

self.logger.debug("Sending new release notification email")
self.logger.debug(f"Using server: {self.config['smtp_server']}:{self.config['smtp_port']}")
with smtplib.SMTP_SSL(self.config["smtp_server"], self.config["smtp_port"], context=context) as server:
try:
server.login(self.config["smtp_username"], self.config["smtp_password"])
server.sendmail(self.config["smtp_sender_email"], self.config["smtp_recipient"], msg.as_string())
except Exception as e:
self.logger.error("Error while sending mail: " + str(e))
self.logger.debug("Sending new release notification email")
self.logger.debug(f"Using server: {self.config['smtp_server']}:{self.config['smtp_port']}")
with smtplib.SMTP_SSL(self.config["smtp_server"], self.config["smtp_port"], context=context) as server:
try:
server.login(self.config["smtp_username"], self.config["smtp_password"])
server.sendmail(self.config["smtp_sender_email"], self.config["smtp_recipient"], msg.as_string())
except Exception as e:
self.logger.error("Error while sending mail: " + str(e))

0 comments on commit 17d7f49

Please sign in to comment.