M guardian/conf.py => guardian/conf.py +5 -5
@@ 16,8 16,8 @@ IRC_CHANNEL = config.get("irc", "channel")
IRKER_HOST = config.get("irc", "host")
IRKER_PORT = int(config.get("irc", "port"))
-MAIL_FROM = config.get('email','mail_from')
-MAIL_TO = [config.get('email','mail_to')]
-SMTP_SERVER = config.get('email','smtp')
-USERNAME = config.get('email','username')
-PASSWORD = config.get('email','password')
+MAIL_FROM = config.get("email", "mail_from")
+MAIL_TO = [config.get("email", "mail_to")]
+SMTP_SERVER = config.get("email", "smtp")
+USERNAME = config.get("email", "username")
+PASSWORD = config.get("email", "password")
M guardian/notification.py => guardian/notification.py +16 -0
@@ 3,6 3,8 @@
import json
import socket
+import smtplib
+from email.mime.text import MIMEText
from guardian import conf
@@ 15,3 17,17 @@ def irker(message):
s.sendall(json.dumps(data).encode("utf-8"))
except socket.error as e:
sys.stderr.write("irkerd: write to server failed: %r\n" % e)
+
+
+def mail(mfrom, mto, message):
+ """Send the notification via mail."""
+ email = MIMEText(message, "plain", "utf-8")
+ email["From"] = mfrom
+ email["To"] = mto
+ email["Subject"] = "Guardian : Alert"
+ # email['Text'] = message
+
+ server = smtplib.SMTP(conf.SMTP_SERVER)
+ server.login(conf.USERNAME, conf.PASSWORD)
+ server.send_message(email)
+ server.quit()