Jul-12-2020, 12:25 PM
Hi,
I'm a newbie here. I'm looking for help to automatically send an email to an address assoicated with a string found in an excel spreadsheet.
I've a camera that takes an image of a number plate, then using pytesseract it reads the number plate characters from the image, searches an excel sheet for the characters and if found, send an email to an address associated with that number plate. So the code successfully takes the image, identifies the characters however I cannot seem to get it send the email. Below is the code I'm using, any help would be great :) Thanks
I'm a newbie here. I'm looking for help to automatically send an email to an address assoicated with a string found in an excel spreadsheet.
I've a camera that takes an image of a number plate, then using pytesseract it reads the number plate characters from the image, searches an excel sheet for the characters and if found, send an email to an address associated with that number plate. So the code successfully takes the image, identifies the characters however I cannot seem to get it send the email. Below is the code I'm using, any help would be great :) Thanks
#Read the number plate text = pytesseract.image_to_string(Cropped, config='--psm 11') print("Detected Number is:", text) cv2.imshow('Number Plate',img) cv2.imshow('Zoomed Image',Cropped) cv2.waitKey(5000) cv2.destroyAllWindows() loc = ("NumberPlateList.xlsx") wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) sheet.cell_value(0, 0) scannedNumberPlateNumber = (text) for i in range(sheet.nrows): if sheet.cell_value(i, 0) == scannedNumberPlateNumber: print('Found in column A - ignore') if sheet.cell_value(i, 2) == scannedNumberPlateNumber: print('Found in column C - send email to ' + sheet.cell_value(i, 3) ) def send_an_email(): toaddr = (+ sheet.cell_value(i, 3)) # To id me = (+ sheet.cell_value(i, 3)) # your id subject = "Your car is illegaly parked. PLEASE MOVE IMMEDIATELY" # Subject msg = MIMEMultipart() msg['Subject'] = subject msg['From'] = me msg['To'] = toaddr msg.preamble = "test " #msg.attach(MIMEText(text)) part = MIMEBase('application', "octet-stream") part.set_payload(open("image.jpg", "rb").read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="image.jpg"') # File name and format name msg.attach(part) try: s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol s.ehlo() s.starttls() s.ehlo() s.login(user = 'XXXXXXXX', password = 'XXXXXX') # User id & password #s.send_message(msg) s.sendmail(me, toaddr, msg.as_string()) s.quit() #except: # print ("Error: unable to send email") except SMTPException as error: print ("Error") # Exception