-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsendemail.py
40 lines (35 loc) · 1.02 KB
/
sendemail.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
import serial
import smtplib
import string
import sys
### GENERAL SETTINGS ###
SERIALPORT = "COM100" # the default com/serial port the receiver is connected to
BAUDRATE = 115200 # default baud rate we talk to Moteino
SUBJECT = "You got snail mail!"
TO = "[email protected]"
FROM = "[email protected]"
text = "The mailbox was opened!"
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
ser = serial.Serial(SERIALPORT, BAUDRATE, timeout=10)
def sendMail():
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login('[email protected]', 'your gmail password or gmail app specific password')
server.sendmail(FROM, [TO], BODY)
server.quit()
while True:
line = ser.readline()
data = line.rstrip().split() #no argument = split by whitespace
print line
if len(data)>=2:
for i in range(1, len(data)):
if data[i]=='MAIL:O':
print '\n\nGOT MAIL!!!!\n\n'
sendMail()