-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.py
64 lines (49 loc) · 1.33 KB
/
logic.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
import smtplib
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import mysql.connector
# login to mysql
db = mysql.connector.connect(
host="localhost", user="root", passwd="", database="email_bot"
)
mycursor = db.cursor()
# select saved emails from database
mycursor.execute("select * from emails;")
data = [i for i in mycursor]
# select contacts from database
mycursor.execute("select * from contacts;")
emails = [i for i in mycursor]
print(emails)
# login to gmail
sender = "cproject290@gmail.com"
password = "thisiscsproject"
context = ssl.create_default_context()
server = smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context)
server.login(sender, password)
# stats
count = 1
total = len(data)
for row in data:
# print(row)
name = str(emails[0][0]) + " " + str(emails[0][1])
receiver = emails[0][2]
# message details
message = MIMEMultipart("alternative")
message["Subject"] = row[1]
message["From"] = sender
message["To"] = receiver
print(message)
# print(receiver)
html = row[2]
# plaintext = MIMEText(text, "plain")
html = MIMEText(html, "html")
# message.attach(plaintext)
message.attach(html)
"""
try:
server.sendmail(sender, receiver, message.as_string())
except:
pass
"""
count += 1