-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailSender.py
60 lines (44 loc) · 1.55 KB
/
EmailSender.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from threading import Thread
sender = "straightouttakengeri@gmail.com"
def send(reciever, img_link):
t = Thread(target=sendemail, args=(reciever, img_link))
t.start()
def sendemail(reciever, img_link):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender, "wthiskengeri")
msg = MIMEMultipart('alternative')
msg['Subject'] = "ALERT: Unauthorized Person Detected"
msg['From'] = sender
msg['To'] = reciever
text = "Do you recognize this person?"
html = """\
<html>
<head></head>
<body>
<p>WatchDog Alert!<br>
<img src=\"""" +img_link+ """\">link</img>
<h5> Deteced Object </h5>
StraightOuttaKengeri<sup>TM</sup> <br>
</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
t = server.sendmail(sender, reciever, msg.as_string())
print "sent"
server.quit()
# Create the body of the message (a plain-text and an HTML version).
# Record the MIME types of both parts - text/plain and text/html.
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
# Send the message via local SMTP server.
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.