Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit f322d7f

Browse files
authored
Merge pull request #25 from Mitesh2499/master
Done with Sending Emails from CSV
2 parents 546296f + 96be540 commit f322d7f

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Send Emails from CSV File
2+
3+
### Emails.csv : - Here CSV file Contain List Of Emails
4+
5+
### Credentials.txt : -Contain information about Yoour Email
6+
7+
1. Your Email Address
8+
2. Your Email Password
9+
10+
### CSV module :- As it is lightweight than Pandas.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import smtplib
2+
import csv
3+
4+
5+
def get_credentials(filepath):
6+
with open("credentials.txt", "r") as f:
7+
Email_Address = f.readline()
8+
Email_Pass = f.readline()
9+
return (Email_Address, Email_Pass)
10+
11+
12+
def login(email_address, email_pass, s):
13+
s.ehlo()
14+
# start TLS for security
15+
s.starttls()
16+
s.ehlo()
17+
# Authentication
18+
s.login(email_address, email_pass)
19+
print("login")
20+
21+
22+
23+
def Send_mail():
24+
s = smtplib.SMTP("smtp.gmail.com", 587)
25+
Email_Address, Email_Pass = get_credentials("./credentials.txt")
26+
login(Email_Address, Email_Pass, s)
27+
28+
29+
# message to be sent
30+
subject = "Welcome to python"
31+
body = """Python is an interpreted, high-level,
32+
general-purpose programming language.\n
33+
Created by Guido van Rossum and first released in 1991,
34+
Python's design philosophy emphasizes code readability\n
35+
with its notable use of significant whitespace"""
36+
message = f"Subject : {subject} \n\n {body}"
37+
38+
with open("emails.csv", newline="") as csvfile:
39+
spamreader = csv.reader(csvfile, delimiter=" ", quotechar="|")
40+
for email in spamreader:
41+
s.sendmail(Email_Address, email[0], message)
42+
print("Send To " + email[0])
43+
44+
# terminating the session
45+
s.quit()
46+
print("sent")
47+
48+
49+
if __name__ == "__main__":
50+
Send_mail()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YourEmail
2+
Yourpass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mithilesh24m@gmail.com
2+
mithilesh24m@gmail.com
3+
mithilesh24m@gmail.com
4+
mithilesh24m@gmail.com

0 commit comments

Comments
 (0)