Skip to content

Commit 436e345

Browse files
Add files via upload
1 parent ae88794 commit 436e345

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

mail.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import smtplib
22
import csv
33
import re
4-
5-
email = ""
6-
password = ""
4+
import time
5+
from os import system, name
6+
from getpass import getpass
7+
8+
def clear():
9+
if name=='nt':
10+
_ = system('cls')
11+
else:
12+
_ = system('clear')
13+
14+
clear()
15+
print("Ensure you have saved your database file in the .csv format in this very directory!")
16+
time.sleep(5)
17+
db = input("Enter the database file name with the extension: ")
18+
email = input("Enter your gmail address: ")
19+
password = getpass("Enter your password: ")
720
server = smtplib.SMTP('smtp.gmail.com', 587)
821
server.starttls()
9-
server.login(username, password)
22+
server.login(email, password)
1023

11-
with open('db.csv') as data:
24+
with open(''+db+'') as data:
1225
row = csv.DictReader(data)
1326
for line in row:
1427
name = line['fullname']
1528
msg = "Hey"+name+" ! Hope you're having a good time!"
1629
add = line['email']
1730
server.sendmail(email, add, msg)
31+
print("Mail sent to "+name+"")
1832

19-
server.quit()
33+
server.quit()

script.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
SMTPserver = ''
2-
sender = ''
3-
4-
USERNAME = ""
5-
PASSWORD = ""
6-
7-
# typical values for text_subtype are plain, html, xml
8-
9-
subject="" # subject of the email
10-
111
import sys
12-
import os
2+
from os import name, system
133
import re
144
import csv
155
import time
6+
from smtplib import SMTP_SSL as SMTP
7+
from email.mime.text import MIMEText
8+
from getpass import getpass
169

17-
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
18-
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
1910

20-
# old version
21-
# from email.MIMEText import MIMEText
22-
from email.mime.text import MIMEText
11+
def clear():
12+
if name=='nt':
13+
_ = system('cls')
14+
else:
15+
_ = system('clear')
16+
17+
clear()
18+
print("Ensure you have saved your database file in the .csv format in this very directory!")
19+
time.sleep(5)
20+
21+
SMTPserver = input("Enter server address: ")
22+
sender = input("Email through which mails are to be sent: ")
23+
USERNAME = input("Enter cpanel username: ")
24+
PASSWORD = getpass("Enter cpanel password: ")
2325

24-
conn = SMTP(SMTPserver)
25-
conn.set_debuglevel(False)
26-
conn.login(USERNAME, PASSWORD)
27-
with open('tbm.csv') as data:
26+
db = input("Enter the database file name with the extension: ")
27+
subject= input("Enter the subject of the email: ")
28+
29+
with open(''+db+'') as data:
2830
row = csv.DictReader(data)
2931
for line in row:
3032
name = line['First Name']
3133
add = line['Email']
3234
text_subtype = 'html'
3335
# content
3436
content="""\
35-
3637
"""
3738
msg = MIMEText(content, text_subtype)
3839
try:
@@ -50,6 +51,4 @@
5051
time.sleep(1)
5152
exit()
5253

53-
conn.quit()
54-
# except:
55-
# sys.exit( "mail failed; %s" % "CUSTOM_ERROR" ) # give an error message
54+
conn.quit()

0 commit comments

Comments
 (0)