Python Forum
Python Automated Email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Automated Email
#1
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

#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
Reply


Messages In This Thread
Python Automated Email - by aidanh26 - Jul-12-2020, 12:25 PM
RE: Python Automated Email - by HarleyQuin - Jul-12-2020, 01:17 PM
RE: Python Automated Email - by aidanh26 - Jul-12-2020, 01:21 PM
RE: Python Automated Email - by HarleyQuin - Jul-12-2020, 02:03 PM
RE: Python Automated Email - by aidanh26 - Jul-12-2020, 02:41 PM
RE: Python Automated Email - by HarleyQuin - Jul-12-2020, 03:48 PM
RE: Python Automated Email - by aidanh26 - Jul-12-2020, 04:14 PM
RE: Python Automated Email - by HarleyQuin - Jul-12-2020, 04:44 PM
RE: Python Automated Email - by aidanh26 - Jul-13-2020, 07:37 AM
RE: Python Automated Email - by HarleyQuin - Jul-13-2020, 09:00 AM
RE: Python Automated Email - by aidanh26 - Jul-13-2020, 04:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help send email by Python using smtplib hangme 6 6,407 Jan-25-2020, 03:31 AM
Last Post: shapeg
  sending email with python shahpy 4 14,394 Oct-03-2016, 10:00 PM
Last Post: shahpy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020