-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsendEmail.py
39 lines (28 loc) · 1.3 KB
/
sendEmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import smtplib
import sys, traceback
from getConfig import getConfigParameters
def sendErrorEmail(errorMessage, subject='Error Message'):
sender = getConfigParameters('senderEmail')
recipientsCommaDelimited = getConfigParameters('receiversEmail')
recipientsCommaDelimited = recipientsCommaDelimited.split(', ')
if( len(errorMessage) > 0 and len(subject) > 0 and len(recipientsCommaDelimited) > 0 and len(sender) > 0 ):
#mod1
sendEmail(sender, recipientsCommaDelimited, subject, errorMessage)
def sendEmail(sender, receiversArray, subject, message):
mailServer = getConfigParameters('mailServer')
if(len(sender) > 0 and len(receiversArray) > 0 and len(subject) and len(message) > 0 and len(mailServer) > 0 ):
toString = ''
for email in receiversArray:
toString = toString + ',' + email
toString = toString[1:]
message = 'From:' + sender + '\n' + 'To:' + toString + '\n' + 'Subject:' + subject + '\n\n' + message;
#print 'toString:', toString
#print ''
#print 'message:', message
try:
smtpObj = smtplib.SMTP(mailServer)
smtpObj.sendmail(sender, receiversArray, message)
print("Successfully sent email")
except:
print("Error: unable to send email")
print(traceback.print_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2],limit=2,file=sys.stdout))