-
Notifications
You must be signed in to change notification settings - Fork 8
/
mail_config.py
executable file
·31 lines (24 loc) · 1.05 KB
/
mail_config.py
1
2
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
import smtplib
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def send_email(image, config):
msg_root = MIMEMultipart('related')
msg_root['Subject'] = 'Security Update'
msg_root['From'] = config.sender_email_address
msg_root['To'] = config.receiver_email_address
msg_root.preamble = 'Raspberry pi security camera update'
msg_alternative = MIMEMultipart('alternative')
msg_root.attach(msg_alternative)
msg_text = MIMEText('Smart security cam found object')
msg_alternative.attach(msg_text)
msg_text = MIMEText('<img src="cid:image1">', 'html')
msg_alternative.attach(msg_text)
msg_image = MIMEImage(image)
msg_image.add_header('Content-ID', '<image1>')
msg_root.attach(msg_image)
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.starttls()
smtp.login(config.sender_email_address, config.sender_email_password)
smtp.sendmail(config.sender_email_address, config.receiver_email_address, msg_root.as_string())
smtp.quit()