aboutsummaryrefslogtreecommitdiffstats
path: root/bin/common/srtool_email.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/common/srtool_email.py')
-rwxr-xr-xbin/common/srtool_email.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/bin/common/srtool_email.py b/bin/common/srtool_email.py
index 103c8be0..c57fa9ab 100755
--- a/bin/common/srtool_email.py
+++ b/bin/common/srtool_email.py
@@ -44,6 +44,8 @@ msg = ''
verbose = False
test = False
+srtErrorLog = 'srt_errors.txt'
+
#################################
# Send the email
#
@@ -67,6 +69,11 @@ def enter_message():
print("Message length is", len(msg))
+def srt_error_log(msg):
+ f1=open(srtErrorLog, 'a')
+ f1.write("|" + msg + "|\n" )
+ f1.close()
+
#################################
# Send the email
#
@@ -135,28 +142,17 @@ def main(argv):
args = parser.parse_args()
# Resolve the arguments
- if args.smtpfrom:
- fromaddr = args.smtpfrom
- else:
- print("ERROR: missing 'from' address")
- exit(1)
if args.smtpto:
toaddrs = args.smtpto
toaddrs = toaddrs.split(',')
else:
- print("ERROR: missing 'to' address")
+ print("ERROR: missing 'to' address", file=sys.stderr)
exit(1)
if args.subject:
subject = args.subject
else:
- print("ERROR: missing 'subject'")
+ print("ERROR: missing 'subject'", file=sys.stderr)
exit(1)
- if args.smtpserver:
- smtpserver = args.smtpserver
- else:
- smtpserver = os.environ.get('SRT_SMTP')
- if not smtpserver:
- smtpserver = 'localhost'
verbose = args.verbose
test = args.test
@@ -164,11 +160,25 @@ def main(argv):
if args.user:
srt_user = args.user
else:
- srt_user = os.environ.get('SRT_USER')
+ srt_user = os.getenv('SRT_EMAIL_USER','')
if args.passwd:
srt_passwd = args.passwd
else:
- srt_passwd = os.environ.get('SRT_PASSWD')
+ srt_passwd = os.getenv('SRT_EMAIL_PASSWD','')
+ # Server settings
+ if args.smtpserver:
+ smtpserver = args.smtpserver
+ else:
+ smtpserver = os.getenv('SRT_EMAIL_SMTP','')
+ if args.smtpfrom:
+ fromaddr = args.smtpfrom
+ else:
+ fromaddr = os.getenv('SRT_EMAIL_FROM','')
+ if not smtpserver or not srt_user or not srt_passwd or not fromaddr:
+ msg = "FATAL ERROR: Missing SMTP('%s'), User('%s'), Password('%s'), and/or From('%s') for email access" % (smtpserver,srt_user,'*******' if srt_passwd else '',fromaddr)
+ print(msg, file=sys.stderr)
+ srt_error_log(msg)
+ exit(1)
# Encryption
if args.tls:
@@ -187,9 +197,13 @@ def main(argv):
elif args.prompt:
enter_message()
else:
- print("ERROR: missing message source")
+ print("ERROR: missing message source", file=sys.stderr)
exit(1)
+ # Debug
+ if verbose:
+ srt_error_log("EMAIL: SMTP('%s'), User('%s'), Password('%s'), From('%s'), args('%s')" % (smtpserver,srt_user,srt_passwd,fromaddr,str(args)))
+
# Send the email
send_email()