From ea315b138dae8ce738c9bb46e42dd0dd77589dcc Mon Sep 17 00:00:00 2001 From: Josh Goldsmith Date: Sun, 14 Jun 2015 10:43:17 -0700 Subject: [PATCH 1/2] Added date timestamp to header Added and populated the "Date" info to the header. Fixes "Missing required header field: 'Date'" errors. --- galeranotify.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/galeranotify.py b/galeranotify.py index 09d274d..e8428df 100644 --- a/galeranotify.py +++ b/galeranotify.py @@ -6,8 +6,9 @@ # Complies with http://www.codership.com/wiki/doku.php?id=notification_command # # Author: Gabe Guillen -# Version: 1.3 -# Release: 10/03/2013 +# Modified by: Josh Goldsmith +# Version: 1.4 +# Release: 5/14/2015 # Use at your own risk. No warranties expressed or implied. # @@ -16,6 +17,7 @@ import sys import getopt import smtplib +import datetime try: from email.mime.text import MIMEText except ImportError: @@ -46,6 +48,9 @@ MAIL_FROM = 'YOUR_EMAIL_HERE' # Takes a list of recipients MAIL_TO = ['SOME_OTHER_EMAIL_HERE'] +# Need Date in Header for SMTP RFC Compliance +DATE = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) + # Edit below at your own risk ################################################################################ def main(argv): @@ -84,7 +89,7 @@ def main(argv): elif opt in ("--index"): message_obj.set_index(arg) try: - send_notification(MAIL_FROM, MAIL_TO, 'Galera Notification: ' + THIS_SERVER, + send_notification(MAIL_FROM, MAIL_TO, 'Galera Notification: ' + THIS_SERVER, DATE, str(message_obj), SMTP_SERVER, SMTP_PORT, SMTP_SSL, SMTP_AUTH, SMTP_USERNAME, SMTP_PASSWORD) except Exception, e: @@ -96,13 +101,14 @@ def main(argv): sys.exit(0) -def send_notification(from_email, to_email, subject, message, smtp_server, +def send_notification(from_email, to_email, subject, date, message, smtp_server, smtp_port, use_ssl, use_auth, smtp_user, smtp_pass): msg = MIMEText(message) msg['From'] = from_email msg['To'] = ', '.join(to_email) msg['Subject'] = subject + msg['Date'] = date if(use_ssl): mailer = smtplib.SMTP_SSL(smtp_server, smtp_port) From ec1998b4b17b4f7bd99a5dca97da0412087d9fcc Mon Sep 17 00:00:00 2001 From: joshin42 Date: Sat, 17 Oct 2015 22:39:05 -0700 Subject: [PATCH 2/2] Update galeranotify.py Fix incorrect ordering of date terms - month and day were swapped --- galeranotify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galeranotify.py b/galeranotify.py index e8428df..106b34f 100644 --- a/galeranotify.py +++ b/galeranotify.py @@ -49,7 +49,7 @@ MAIL_FROM = 'YOUR_EMAIL_HERE' MAIL_TO = ['SOME_OTHER_EMAIL_HERE'] # Need Date in Header for SMTP RFC Compliance -DATE = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) +DATE = datetime.datetime.now().strftime( "%m/%d/%Y %H:%M" ) # Edit below at your own risk ################################################################################