def mail_server(username, password): sender = username mail_sender = MailSender(username, password) logger.info('Mail server initialized and running sucessful') while True: try: if keyboard.is_pressed('ENTER'): # if pir.motion_detected: try: cam.saveSnapshot('image.jpg', timestamp=1) # capture() images = [{'id': 'Person', 'path': 'image.jpg'}] logger.info('Sending photo via email') mail_sender.send(sender, ['*****@*****.**'], 'Person alert!', images=images) logger.info('Photo send to [email protected]') except: logger.error('Photo send via email failed') if keyboard.is_pressed('Ctrl + c'): logger.info('Ctrl + c pressed exiting program') sys.exit(0) except: break
def update_callback(updated_webpages, credentials, email_recipients, email_enabled): msg = '' data_path = os.path.join(os.path.dirname(sys.argv[0]), 'data') for p in updated_webpages: p.toFile(data_path) msg += p.getData(strip_header=False) updated_webpages.remove(p) logger.debug('Notification:\n' + msg) if email_enabled: mailer = MailSender(credentials) mailer.send(msg, email_recipients) else: logger.info('[>] EMAIL THAT WOULD BE SENT:\n%s\n' % msg)
if matches[best_match_index]: name = known_face_names[best_match_index] face_names.append(name) process_this_frame = not process_this_frame if face_names == []: if not state == 1: state =1 logger.info('No face found') led.off() elif name == "Unknown": if not state == 2: state = 2 logger.info('Unknown face found') led.off() elif not state == 3: state = 3 logger.info('Matching face found') for face_name in face_names: logger.info('Welcome %s',face_name) led.on() cv2.imwrite('image.jpg', frame) if pir.motion_detected: try: images = [{'id': 'Person', 'path': 'image.jpg'}] logger.info('Sending photo via email') mail_sender.send(sender, ['*****@*****.**'], 'Person alert!', images=images) logger.info('Photo send to [email protected]') except: logger.error('Photo send via email failed')
writer = csv.writer(file) writer.writerow([serial, name, batch, contact, email]) file = open('serial.txt', 'w') serial = int(serial) + 1 file.write(str(serial)) file.close() from mailsender import MailSender username = '******' password = '******' sender = username images = list() images.append({'id': 'logo', 'path': 'output.jpg'}) with open('template.html') as template_html, open( 'template.txt') as template_plain: message_html = template_html.read() message_plain = template_plain.read() mail_sender = MailSender(username, password) mail_sender.send(sender, [email], 'Lucky draw ticket.', message_html=message_html, message_plain=message_plain, images=images) print('..') os.remove("output.jpg") print('Email Send')