-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_alert_function.py
35 lines (27 loc) · 1.13 KB
/
email_alert_function.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
32
33
34
35
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
def em(receiver):
message = MIMEMultipart('related')
msg_content = '''<html><body>
<p> ALERT Beast, something mischievous happening. Take a close look 🤔 </p>
<p><img src="cid:[email protected]" width="300" height="300"></p>
</body></html>'''
message.attach(MIMEText((msg_content), 'html'))
with open('sp2.jfif', 'rb') as image_file:
image = MIMEImage(image_file.read())
image.add_header('Content-ID', '<[email protected]>')
image.add_header('Content-Disposition', 'inline', filename='sp2.jfif')
message.attach(image)
sender = "[email protected]"
password = "novebhfswebflrzt"
message['From'] = sender
message['To'] = receiver
message['Subject'] = 'Python Test E-mail'
msg_full = message.as_string()
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(sender, password)
server.sendmail(sender,[receiver],msg_full)
server.quit()