Hi i am trying to pass a list to my SendMail function and i am getting values like this for list['abc','cde','ijk']
output abc
abc,cde
abc,cde,ijk
.I need my function to run once and give me the final list only which is list['abc','cde','ijk']
. The original list is a collection of unmatched files names. here is my code please help me. And i am receiving email for each output i need one email
##Packages used
import os
import re
import sys
import glob
import pandas as pd
##Send mail function using unix sendmail
def sendMail(msg):
a=''
for i in msg:
a+="%s
" %i
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = os.popen("%s -t" % sendmail_location, "w")
p.write("From: %s
" % "abc@123.com")
p.write("To: %s
" % "abc@123.com")
p.write("Subject: File Name Error
")
p.write("
") # blank line separating headers from body
p.write("
"+a)
print("
"+a)
status = p.close()
if status != 0:
print("Sendmail exit status", status)
match=[]
not_match=[]
try:
for file in glob.glob('*.csv'):
r = re.search(r'sales_abc_(20[0-9][0-9])-([1-9]|1[0-2]|0[0-9])-([1-9]|1[0-9]|2[0-9]|3[0-1]|0[0-9])-[0-9]{2}_[a-z0-9]{3,5}.csv', file)
if r:
match.append(file)
if not r:
not_match.append(file)
sendMail(not_match)
except Exception:
not_found="File Not Found"
sendMail(not_found)