Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.base import MIMEBase
- from email import encoders
- import csv
- from random import randint
- from time import sleep
- def send_mail(fromaddr, frompasswd, toaddr, msg_subject, msg_body, file_path):
- try:
- msg = MIMEMultipart()
- print("[+] Message Object Created")
- except:
- print("[-] Error in Creating Message Object")
- return
- msg['From'] = fromaddr
- msg['To'] = toaddr
- msg['Subject'] = msg_subject
- body = msg_body
- msg.attach(MIMEText(body, 'plain'))
- filename = file_path
- attachment = open(filename, "rb")
- p = MIMEBase('application', 'octet-stream')
- p.set_payload((attachment).read())
- encoders.encode_base64(p)
- p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
- try:
- msg.attach(p)
- print("[+] File Attached")
- except:
- print("[-] Error in Attaching file")
- return
- try:
- #s = smtplib.SMTP('smtp.gmail.com', 587)
- s = smtplib.SMTP('mail.iitp.ac.in', 587)
- print("[+] SMTP Session Created")
- except:
- print("[-] Error in creating SMTP session")
- return
- s.starttls()
- try:
- s.login(fromaddr, frompasswd)
- print("[+] Login Successful")
- except:
- print("[-] Login Failed")
- text = msg.as_string()
- try:
- s.sendmail(fromaddr, toaddr, text)
- print("[+] Mail Sent successfully")
- except:
- print('[-] Mail not sent')
- s.quit()
- def isEmail(x):
- if ('@' in x) and ('.' in x):
- return True
- else:
- return False
- f = open('found_details.csv', 'r')
- reader = csv.reader(f)
- FROM_ADDR = "email@iitp.ac.in"
- FROM_PASSWD = "Change"
- Subject = "Mandatory QR Code for IITP Gate Entry/Exit "
- Body ='''
- Dear Student,
- '''
- from datetime import datetime
- start_time = datetime.now()
- #what a ever is the limit of your sending mails, like gmail has 500.
- max_count = 9999999
- count=0
- last_email = open("last_email.txt","a")
- data_list = [row for row in reader]
- f.close()
- for row in data_list:
- file_path = 'qrcodes\\'+row[1] + '.png'
- if isEmail(row[8]) and count <=max_count:
- count+=1
- print(row[8])
- last_email.write(row[8].strip()+"\n")
- send_mail(FROM_ADDR, FROM_PASSWD, row[8], Subject, Body, file_path)
- if isEmail(row[9]) and count <=max_count:
- count+=1
- print(row[9])
- last_email.write(row[9].strip()+"\n")
- send_mail(FROM_ADDR, FROM_PASSWD, row[9], Subject, Body, file_path)
- print("Count Value: ", count)
- print("Sleeping . .. . ")
- sleep(randint(1,3))
- if count == max_count:
- break
- print("Count Max is reached: " ,count)
- last_email.close()
- end_time = datetime.now()
- print('Duration: {}'.format(end_time - start_time))
Add Comment
Please, Sign In to add comment