-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
100 lines (74 loc) · 2.85 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
def emailv(hname,vname,vphone,vmail,intime,outtime):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
# from message import *
fromaddr = "email from which mail has to be sent"
toaddr = vmail
# instance of MIMEMultipart
msg = MIMEMultipart()
# storing the senders email address
msg['From'] = fromaddr
# storing the receivers email address
msg['To'] = toaddr
# storing the subject
msg['Subject'] = "Visitor Information"
# string to store the body of the mail
body = "Visitor's Name: "+ vname + "\nPhone Number: "+ str(vphone) + "\nVisitor's Email: "+ vmail + "\nIntime: " + str(intime) + "\nOut time: " + str(outtime[0][0]) + "\nHost: "+ str(hname)
#text = body.astype(str)
# attach the body with the msg instance
msg.attach(MIMEText(body , 'plain'))
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for security
s.starttls()
# Authentication
s.login(fromaddr, "password")
# Converts the Multipart msg into a string
text = msg.as_string()
# sending the mail
s.sendmail(fromaddr, toaddr, text)
# terminating the session
s.quit()
print("Mail sent to the Visitor.")
#vmessage(body,vphone) # to send sms to the visitor uncomment this line.
return 0
def emailh(hmail,vname,vphone,vmail,intime,hphone):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
#from message import *
fromaddr = "email from which mail has to be sent"
toaddr = hmail
# instance of MIMEMultipart
msg = MIMEMultipart()
# storing the senders email address
msg['From'] = fromaddr
# storing the receivers email address
msg['To'] = toaddr
# storing the subject
msg['Subject'] = "Visitor Information"
# string to store the body of the mail
body = "Visitor's Name: "+ vname + "\nPhone Number: "+ str(vphone) + "\nVisitor's Email: "+ vmail + "\nIntime: " + str(intime)
#text = body.astype(str)
# attach the body with the msg instance
msg.attach(MIMEText(body , 'plain'))
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for security
s.starttls()
# Authentication
s.login(fromaddr, "password")
# Converts the Multipart msg into a string
text = msg.as_string()
# sending the mail
s.sendmail(fromaddr, toaddr, text)
# terminating the session
s.quit()
print("Mail sent to the Host")
hmessage(body, hphone) # to send sms to the host uncomment this line.
return 0