Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions projects/Send_email_from_csv/Readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
# Send Emails from CSV File

### Emails.csv : - Here CSV file Contain List Of Emails
This project contains a simple bulk email script
which sends the same message to a list of recipients.

### Credentials.txt : -Contain information about Yoour Email

1. Your Email Address
2. Your Email Password
## Dependencies

### CSV module :- As it is lightweight than Pandas.
This project only requires the Python standard library
(more specifically, the `csv`, `email`, and `smtplib` modules).


## Running the script

The script requires two configuration files:

* `emails.csv` should contain the email addresses to send the message to.
* `credentials.txt` should contain your SMTP server login credentials,
with your user name and your password on sepate lines,
with no additional whitespace or other decorations.

The project's directory contains two example files which you'll
probably both want and need to edit.

Once you have these files set up, simply

```
python Send_emails.py
```


## Development ideas

A proper email sender would use `Cc:` or `Bcc:` and send the same
message just once.

Don't play frivolously with this; your email provider,
and/or the recipient's,
may have automatic filters which quickly block anyone who sends
multiple identical messages.

The script simply hardcodes the conventions for Gmail.com.
Other providers may use a different port number and authentication regime.
28 changes: 15 additions & 13 deletions projects/Send_email_from_csv/Sending_mail.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import smtplib
import csv
from email.message import EmailMessage
import smtplib


def get_credentials(filepath):
with open("credentials.txt", "r") as f:
Email_Address = f.readline()
Email_Pass = f.readline()
return (Email_Address, Email_Pass)
email_address = f.readline()
email_pass = f.readline()
return (email_address, email_pass)


def login(email_address, email_pass, s):
Expand All @@ -19,26 +20,27 @@ def login(email_address, email_pass, s):
print("login")



def Send_mail():
def send_mail():
s = smtplib.SMTP("smtp.gmail.com", 587)
Email_Address, Email_Pass = get_credentials("./credentials.txt")
login(Email_Address, Email_Pass, s)

email_address, email_pass = get_credentials("./credentials.txt")
login(email_address, email_pass, s)

# message to be sent
subject = "Welcome to python"
subject = "Welcome to Python"
body = """Python is an interpreted, high-level,
general-purpose programming language.\n
Created by Guido van Rossum and first released in 1991,
Python's design philosophy emphasizes code readability\n
with its notable use of significant whitespace"""
message = f"Subject : {subject} \n\n {body}"

message = EmailMessage()
message.set_content(body)
message['Subject'] = subject

with open("emails.csv", newline="") as csvfile:
spamreader = csv.reader(csvfile, delimiter=" ", quotechar="|")
for email in spamreader:
s.sendmail(Email_Address, email[0], message)
s.send_message(email_address, email[0], message)
print("Send To " + email[0])

# terminating the session
Expand All @@ -47,4 +49,4 @@ def Send_mail():


if __name__ == "__main__":
Send_mail()
send_mail()