-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailParser.py
63 lines (51 loc) · 2.61 KB
/
emailParser.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
61
62
63
#!/usr/bin/evn python
####################### EMAIL CREATION SECTION START ##############################
# This code is used to email out a notification if the magnetic door sensor has #
# been triggered. #
# Begin mail setup, this code is written for GMAIL but you could easily re-write #
# the current code by changing the GMAIL setup properties with Hotmail or what #
# ever smtp mail service. #
###################################################################################
def emailalert():
import smtplib
from time_convert import door_timestamp
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# GMAIL user setup #
gmail_sender = '[email protected]'
gmail_passwd = 'Monkeybutt2'
you = "[email protected]"
# GMAIL SMTP Server connect
smtp_host = 'smtp.gmail.com'
smtp_port = 587
server = smtplib.SMTP( smtp_host, smtp_port )
server.ehlo( )
server.starttls( )
server.login( gmail_sender, gmail_passwd )
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart( 'alternative' )
msg['Subject'] = 'TEST TEST - Do you know where you daughter is? - TEST TEST'
msg['From'] = gmail_sender
msg['To'] = you
b1 = '<html><head></head><body><p><br><br>Do you know where you daughter is?<br><br>Your front door was opened at: '
b2 = door_timestamp( 0 )
b3 = ' </p><BR><BR><BR>The Alarm!<br><br>John Robinson</body></html>'
# Create the body of the message (a plain-text and an HTML version).
text = (
"Do you know where you daughter is? \n Your front door was opened at: ", door_timestamp( 0 ), "\n\n The Alarm")
html = (b1 + b2 + b3)
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText( text, 'plain' )
part2 = MIMEText( html, '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.
msg.attach( part1 )
msg.attach( part2 )
# Send the message via gmail SMTP server.
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
server.sendmail( gmail_sender, [you], msg.as_string( ) )
server.quit( )
####################### EMAIL CREATION SECTION END ###############################