-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_mail.py
56 lines (47 loc) · 1.88 KB
/
alert_mail.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
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import geocoder
def do_this(charles,bin_laden):
strFrom = '[email protected]'
strTo = '[email protected]'
g = geocoder.ip('me')
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Alert! Criminal Suspected.'
msgRoot['From'] = 'your email'
msgRoot['To'] = 'reciever email'
#msgRoot.preamble = 'This is a multi-part message in MIME format.'
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgBody = MIMEText('Criminal(s) has been suspected. Please find the attached photo(s) of the suspected. The lattitude and longitude of the suspected are: ')
msgLocation=MIMEText('location:'+str(g.latlng), 'plain')
msgAlternative.attach(msgBody)
msgText = MIMEText('<b>Criminal(s) has been suspected. Please find the attached photo(s) of the suspected. The lattitude and longitude of the suspected are:</b><br><br>'
'<img src="cid:image1">'
'<br>'
'<br>'
'<img src="cid:image2">'
'<br>'
'<br>'
'Sending Attachment', 'html')
msgAlternative.attach(msgText)
msgAlternative.attach(msgLocation)
if bin_laden==1:
fp = open('bin_laden.jpg', 'rb')
msgImage1 = MIMEImage(fp.read())
fp.close()
msgImage1.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage1)
if charles==1:
fp = open('charles.jpg', 'rb')
msgImage2 = MIMEImage(fp.read())
fp.close()
msgImage2.add_header('Content-ID', '<image2>')
msgRoot.attach(msgImage2)
import smtplib
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.starttls()
smtp.login(strFrom, "your password")
smtp.sendmail(strFrom, strTo, msgRoot.as_string())
print('sent')
smtp.quit()