Skip to content
Browse files

Allow SMTP credentials to be supplied

  • Loading branch information...
1 parent 7f11b06 commit 2d925e1dee3070d7e5d87df6b3b85c55c3a4a47f @damycra damycra committed Apr 17, 2013
Showing with 11 additions and 1 deletion.
  1. +3 −0 superlance/fatalmailbatch.py
  2. +8 −1 superlance/process_state_email_monitor.py
View
3 superlance/fatalmailbatch.py
@@ -29,6 +29,9 @@
[--toEmail=<email address>]
[--fromEmail=<email address>]
[--subject=<email subject>]
+ [--smtpHost=<smtp server>]
+ [--userName=<smtp server username>]
+ [--password=<smtp server password]
Options:
View
9 superlance/process_state_email_monitor.py
@@ -46,7 +46,10 @@ def parse_cmd_line_options(cls):
help="SMTP server hostname or address")
parser.add_option("-e", "--tickEvent", dest="eventname", default="TICK_60",
help="TICK event name (defaults to TICK_60)")
-
+ parser.add_option("-u", "--userName", dest="smtp_user", default="",
+ help="SMTP server user name (defaults to nothing)")
+ parser.add_option("-p", "--password", dest="smtp_password", default="",
+ help="SMTP server password (defaults to nothing)")
(options, args) = parser.parse_args()
return options
@@ -84,6 +87,8 @@ def __init__(self, **kwargs):
self.to_emails = kwargs['to_emails']
self.subject = kwargs.get('subject')
self.smtp_host = kwargs.get('smtp_host', 'localhost')
+ self.smtp_user = kwargs.get('smtp_user')
+ self.smtp_password = kwargs.get('smtp_password')
self.digest_len = 76
def send_batch_notification(self):
@@ -125,6 +130,8 @@ def send_email(self, email):
def send_smtp(self, mime_msg, to_emails):
s = smtplib.SMTP(self.smtp_host)
try:
+ if self.smtp_user and self.smtp_password:
+ s.login(self.smtp_user,self.smtp_password)
s.sendmail(mime_msg['From'], to_emails, mime_msg.as_string())
except:
s.quit()

0 comments on commit 2d925e1

Please sign in to comment.
Something went wrong with that request. Please try again.