-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsms.py
More file actions
59 lines (47 loc) · 1.78 KB
/
sms.py
File metadata and controls
59 lines (47 loc) · 1.78 KB
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
#Sender email
email = "cmpe272project2020@gmail.com"
password = "CMPE@272"
#reciever number and email address
#sms_gateway = '5855246544@tmomail.net' #tmomail.net is used for tmobile numbers
#receiver_email = "pranjay.sagar@sjsu.edu"
# Using smtp server we use is gmail smtp server ( the port comes by default with the gmail server)
smtp = "smtp.gmail.com"
port = 587
#what we want the body and subject contents to be
subject_content="ALERT 911\n"
body_content_1="Gunshot sound heard, we are "
body_content_2="% sure, Need assistance!!\n"
#login
# To send sms text message
def send_msg(modileNo,percentage):
server = smtplib.SMTP(smtp,port)
server.starttls()
server.login(email,password)
sms_gateway = str(modileNo) + '@tmomail.net'
textmsg = MIMEMultipart()
textmsg['From'] = "SOUND PROFOUND"
textmsg['To'] = sms_gateway
textmsg['Subject'] = subject_content
body = body_content_1 + str(percentage) + body_content_2
textmsg.attach(MIMEText(body, 'plain'))
sms = textmsg.as_string()
server.sendmail(email,sms_gateway,sms)
server.quit()
# Send Email
def send_email(receiver_email,percentage):
#starts pythons email server
server = smtplib.SMTP(smtp,port)
server.starttls()
server.login(email,password)
emailMessage = MIMEMultipart()
emailMessage['From'] = "SOUND PROFOUND"
emailMessage['To'] = receiver_email
emailMessage['Subject'] = subject_content
body = body_content_1 + str(percentage) + body_content_2
emailMessage.attach(MIMEText(body, 'plain'))
mailAlert = emailMessage.as_string()
server.sendmail(email,receiver_email,mailAlert)
server.quit()