Commit 0409541b authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Allow to enable/disable email notifications.

parent cca031d8
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ minutes = 1
seconds = 30

[mail]
enable_notifications = false
smtp_server = <smtp_server_hostname>
smtp_port = 25
no_reply_email = <noreply-vospace@mydomain.it>
+19 −14
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ class Mailer(object):
        self.smtpServer = params["smtp_server"]
        self.smtpPort = params.getint("smtp_port")
        self.sender = params["no_reply_email"]
        self.enabled = params.getboolean("enable_notifications")
        params = config.loadSection("logging")
        self.logger = logging.getLogger(__name__)
        logLevel = "logging." + params["log_level"]
@@ -67,6 +68,8 @@ class Mailer(object):

    def send(self):
        """Send email message."""
        if self.enabled:
            self.logger.debug("E-mail notifications enabled.")
            try:
                smtpObj = smtplib.SMTP(self.smtpServer, self.smtpPort)
                smtpObj.send_message(self.message)
@@ -81,6 +84,8 @@ class Mailer(object):
            except SMTPException:
                logMsg = "Cannot send email message."
                self.logger.exception(logMsg)
        else:
            self.logger.debug("E-mail notifications disabled.")


# Test 1