Welcome To Just IT CluB
The best place where you can get free and cracked software and awesome tutorials include tip and trick that never seen on web before or much rare.

Tuesday, December 24, 2013

How To Send Bulk Email Sender [python]

This is a bulk email sending script in python. It doesnt require any dependency. The email of the sender needs to be of gmail and the list of recepients emails should be in a .txt file . Each email should be on a single line else this script will not work. Plz comment and rep+ if you like it.

Code:

import smtplib
import sys

try:
    print "-----------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------"
    print "-----------------++++++++++++++++++++++++++++++++++++++--Asad Rafiq--++++++++++++++++++++++++++++++++++++++++++-----------------"
    print "-----------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------"
    
    # get the txt file containing the email addresses of recepients. Each email is written on a separate line
    # for example
    # someone@some.com
    # otherperson@other.com
    # and so on
    
    users = raw_input("\n[email sender]  recepients file name:  ")
    if ".txt" in users:
        pass
    else:
        print "[email sender]  this is not a valid txt file"
        sys.exit()

    # get the list of recepients
    recepients = []
    try:
        with open(users) as i:
            user_list = i.readlines()
        for i in user_list:
            recepients.append(i.strip("\n"))
    except IOError :
        print "[email sender]  invalid recepients file"
        sys.exit()

    # get the required information from the user
    FROM = raw_input("[email sender]  from:  ")
    TO = recepients 
    SUBJECT = raw_input("[email sender]  subject:  ")
    TEXT = raw_input("[email sender]  message:  ")



    # Prepare actual message
    headers = ["From: " + FROM,
               "Subject: " + SUBJECT,
               "To: " + ", ".join(TO),
               "MIME-Version: 1.0",
               "Content-Type: text/html"]
    headers = "\r\n".join(headers)
    body = "" + TEXT + ""
    
    # Credentials 
    username = raw_input("[email sender]  your gmail username:  ")
    password = raw_input("[email sender]  your gmail password:  ")

    # The actual mail send
    print "[email sender]  sending....."
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(username,password)
    server.sendmail(FROM, TO, headers + "\r\n\r\n" + TEXT)
    server.quit()
    print "[email sender]  email sent to all recepients"
except KeyboardInterrupt :
    print "\n[email sender]  program was closed by the user\n"

No comments:

Post a Comment

We do receive a lot of comments each day and those comments are moderated by the human being not automated robots. So, Please avoid doing spam and posting links in comments otherwise comment will not be published. We can't tolerate anymore. Thanks for understanding!