Merge pull request #4 from joshin42/master

Fix: Added date timestamp to header
This commit is contained in:
Gabe Guillen 2015-12-07 18:55:50 -08:00
commit cb74462f4e

View File

@ -6,8 +6,9 @@
# Complies with http://www.codership.com/wiki/doku.php?id=notification_command # Complies with http://www.codership.com/wiki/doku.php?id=notification_command
# #
# Author: Gabe Guillen <gguillen@gesa.com> # Author: Gabe Guillen <gguillen@gesa.com>
# Version: 1.3 # Modified by: Josh Goldsmith <joshin@hotmail.com>
# Release: 10/03/2013 # Version: 1.4
# Release: 5/14/2015
# Use at your own risk. No warranties expressed or implied. # Use at your own risk. No warranties expressed or implied.
# #
@ -16,6 +17,7 @@ import sys
import getopt import getopt
import smtplib import smtplib
import datetime
try: from email.mime.text import MIMEText try: from email.mime.text import MIMEText
except ImportError: except ImportError:
@ -46,6 +48,9 @@ MAIL_FROM = 'YOUR_EMAIL_HERE'
# Takes a list of recipients # Takes a list of recipients
MAIL_TO = ['SOME_OTHER_EMAIL_HERE'] MAIL_TO = ['SOME_OTHER_EMAIL_HERE']
# Need Date in Header for SMTP RFC Compliance
DATE = datetime.datetime.now().strftime( "%m/%d/%Y %H:%M" )
# Edit below at your own risk # Edit below at your own risk
################################################################################ ################################################################################
def main(argv): def main(argv):
@ -84,7 +89,7 @@ def main(argv):
elif opt in ("--index"): elif opt in ("--index"):
message_obj.set_index(arg) message_obj.set_index(arg)
try: 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, str(message_obj), SMTP_SERVER, SMTP_PORT, SMTP_SSL, SMTP_AUTH,
SMTP_USERNAME, SMTP_PASSWORD) SMTP_USERNAME, SMTP_PASSWORD)
except Exception, e: except Exception, e:
@ -96,13 +101,14 @@ def main(argv):
sys.exit(0) 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): smtp_port, use_ssl, use_auth, smtp_user, smtp_pass):
msg = MIMEText(message) msg = MIMEText(message)
msg['From'] = from_email msg['From'] = from_email
msg['To'] = ', '.join(to_email) msg['To'] = ', '.join(to_email)
msg['Subject'] = subject msg['Subject'] = subject
msg['Date'] = date
if(use_ssl): if(use_ssl):
mailer = smtplib.SMTP_SSL(smtp_server, smtp_port) mailer = smtplib.SMTP_SSL(smtp_server, smtp_port)