mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
added email sending script using python
This commit is contained in:
parent
d096262318
commit
3bc9d119cf
32
Bulk Email Sender/README.md
Normal file
32
Bulk Email Sender/README.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
## Bulk Email Sender
|
||||
|
||||
If you want to send same mail to a large number of emails ids, this script is perfect for you.
|
||||
|
||||
### We are using smtplib module for email sending
|
||||
|
||||
Requirements:
|
||||
- pip install smtplib
|
||||
- pip install pandas
|
||||
|
||||
#### Flow
|
||||
|
||||
smtplib(Simple Mail Transfer Protocol)
|
||||
|
||||
1. Initialise the credentials for your sending emails ("SenderAddress" and "password" line 5 in main.py)
|
||||
2. Read the excel file for emails ("e" line 12 in main.py)
|
||||
3. Converting excel formatted column into python list. ("emails" line 15 in main.py)
|
||||
4. Create an instance of smtplib.SMTP class ("server" line 18 in main.py)
|
||||
5. Basic setup : starting the instance and logging in process (line 21 in main.py)
|
||||
6. Initialise the content to various string variables which constitute the main content of your email. (line 25 in main.py)
|
||||
7. Loop through all emails in the list and send the emails. (line 35 in main.py)
|
||||
|
||||
#### NOTE
|
||||
If you make any changes main.py, please mention it in README.md (this file). A better documentation makes the process of development faster.
|
||||
|
||||
---
|
||||
Author - Saumitra Jagdale
|
||||
|
||||
|
||||
|
||||
|
||||
|
37
Bulk Email Sender/main.py
Normal file
37
Bulk Email Sender/main.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import pandas as pd
|
||||
import smtplib
|
||||
|
||||
# Initialise Credentials
|
||||
SenderAddress = "abc@gmail.com"
|
||||
password = "Enter Your Password"
|
||||
''' example
|
||||
password="123456"
|
||||
'''
|
||||
|
||||
# Read the email addresses from excel sheet
|
||||
e = pd.read_excel("test.xlsx")
|
||||
|
||||
# Converting Emails in list format
|
||||
emails = e['Emails'].values
|
||||
|
||||
# Creating instance of subclass SMTP inside smtplib class
|
||||
server = smtplib.SMTP("smtp.gmail.com", 587)
|
||||
|
||||
# Setup
|
||||
server.starttls()
|
||||
server.login(SenderAddress, password)
|
||||
|
||||
# Initialise the content
|
||||
greeting = "Dear Receiver,"
|
||||
msg="Main Content"
|
||||
link="Any URLS"
|
||||
end="Ending Greets"
|
||||
regards="With Regards"
|
||||
name="Sender's name"
|
||||
subject = "Subject"
|
||||
body = "Subject: {}\n\n{}\n\n{}\n\n{}\n\n{}\n\n{}\n{}".format(subject,greeting,msg,link,end,regards,name)
|
||||
|
||||
# Loop to send mail to all email ids
|
||||
for email in emails:
|
||||
server.sendmail(SenderAddress, email, body)
|
||||
server.quit()
|
BIN
Bulk Email Sender/test.xlsx
Normal file
BIN
Bulk Email Sender/test.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user