Python Code for Bulk Email sender-Group wise

Email had become a very essential part of our life. We use to send emails on daily basis for various needs. Some times we have to send emails for promotion / marketing or simply to inform our readers.

The existing code was not able to perform the desired task and they also copy all the email id either in CC or in BCC so each and every one was able to get all the existing email IDs.

Free bulk emailer
Free bulk emailer

Other free bulk email solutions ask us to store our email list on their servers and to use their services every time we have to login and use the same.

Our simple python code is going to solve all these issues one by one and help you to spread your words in your own way.

Pr-requisite for Bulk Emailer

  1. xlrd python package for reading excel files
  2. smtplib python module to connect from smtp email server
  3. time module for delaying each email for 15 second
  4. email.mime.text module to format any raw text into email header
#-------------------------------------------------------------------------------
# Name:        Bulk Email Sender using Excel file and 
# Purpose:     Program reads name and email Id from Excel file and send to all the members
# Author:      rakesh  kumar
# Created:     11-02-2018
# Copyright:   rakesh kumar
# Licence:     Private
#-------------------------------------------------------------------------------
import xlrd
import time
import smtplib
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
textfile ="abcd.txt"
fp = open(textfile, 'r')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

me ='rakesh@binarynote.com'
you = 'support@binarynote.com'

msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

password = input("Enter your password")

book = xlrd.open_workbook("phone.xlsx")
sheet = book.sheet_by_index(0)
count = sheet.nrows
for rx in range(1,sheet.nrows):
    rec_email = sheet.cell_value(rx,2)
    rec_name  = sheet.cell_value(rx,0)
    msg['To'] = rec_email
    connection = smtplib.SMTP_SSL('smtp.google.com',465)
    connection.ehlo()
    #connection.starttls()
    connection.login('rakesh@binarynote.com',password)
    connection.sendmail(me,[rec_email],msg.as_string())
    connection.quit()
    positionStr = "Total : "+str(rx).rjust(4) +" out of  : "+ str(count-1).rjust(4) +" send"
    print(positionStr, end='')
    time.sleep(15)
    print('\b' * len(positionStr), end='', flush=True)
    
print('\n\n Emails pushed...\n\n')

The above bulk email sending program, basically is using two files

  1. abcd.txt file  This file contains your actual email that you want to push – sample file you can Download Bulk Emailer using this link
  2. phone.xlsx    This file contains the name and email IDs of all your recipients. Excel sheet containing Email address download it now.

How to run Bul Email sender

  • Install all the desired modules using pip installation command
  • Copy all the files in the same folder as right now we have not taken files destinations from the program
  • Change the Email ID details as right now I am using my own Email ID details and password.
  • This program is using SSL layer for email verification, this is the main reason for using smtplib.SMTP_SSL(‘smtp.google.com’,465) and port no 465
  • If you are using TLS for verification then use smtplib.STMP(“smtp.google.com”,587) in place of smtplib.SMTP_SSL(“smtp.google.com”,465) and also un-comment #connection.starttls()
  • Run your program and enjoy your own Bulk Email sending program.

Note : Right now, I am working on this project, If you have any suggestion to improve this program. Please feel free to log your comments.

%d bloggers like this: