def sendEmail(emailSubject,body):
”’
This function is will send email updates to the recipient
@toRecipient: mail id to which mail will be sent
@emailSubject: subject of the mail
@body: body of the mail
”’
sender = ‘dev1@dev.com’
#list receivers = [toRecipient]
#receivers = [toRecipient]
receivers= ciVariables.emailRecipient.split(“,”)
#message = “””From: From CI -Admin
#To: To Dev Team
#Subject: emailSubject
#body
#”””
msg = MIMEMultipart()
msg[‘From’]=”From Daily CI Admin -” + sender
listOfRecievers = len(receivers)
print(listOfRecievers)
recieversName=””
for i in range(listOfRecievers):
recieversName = recieversName +receivers[i]+”;”
print(recieversName)
msg[‘To’]= recieversName
msg[‘Subject’]=emailSubject
msgbody = body
msg.attach(MIMEText(msgbody, ‘plain’))
text = msg.as_string()
#login to SMTP server details
username = ‘dev1@dev’
password = ‘welcome123’
try:
smtpObj= smtplib.SMTP(‘msi-vmdevrcap’,25)
smtpObj.login(username,password)
smtpObj.sendmail(sender, receivers, text)
smtpObj.quit()
print (“Successfully sent email”)
except Exception:
print (“Error: unable to send email”)
rem # Sub process to send Email
:SendEMail
call:GetDateTime
@echo %DD%-%MM%-%YY% %hr%:%min%:%sec% “INFO: Sending status mail started to %Recipient%”>>%LOGFILE%
echo %Recipient%
echo %EMAIL_SUB%
echo %EMAIL_MESSAGE%
python -c ^
“import ciFunctions ; ^
ciFunctions.sendEmail(“%EMAIL_SUB%”,”%EMAIL_MESSAGE%”)”
call:GetDateTime
@echo %DD%-%MM%-%YY% %hr%:%min%:%sec% “INFO: Mail sent successfully to %Recipient%”>>%LOGFILE%