Python script to send emails with pmta or other mta

This is my 1st Python simple program to send Email with Pmta or other MTA, you can add any smtp, 
i have right this program in 2 ways , one with multi-thread and other with multi-process

Multi-process good if you have good CPU in your PC or server 

for increase speed you can increase number of emails process in one time  
replace 60 to your number 

#line 59# i1 = int(y + 60 )

{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{   {}}}}}}}}}}}}}}}}}}}}}}}}}}}

 from multiprocessing import Process
 import smtplib
 import csv
 import requests
 from email.mime.multipart import MIMEMultipart
 from email.mime.base import MIMEBase
 from email.mime.text import MIMEText
 from email import encoders
 import time
 msg = MIMEMultipart()
 reader = csv.DictReader(open(r"path_toemails.csv"))
 email_s = ["[email protected]"]
 for raw in reader:
     for key, i_1 in raw.items():
 html = """
 your html code
 msg['Subject'] = 'Subject line'
 msg['Unsubscribe'] = "<{}>"
 msg['From'] = "from line <[email protected]>"
 def func(i):
     try :
         msg['To'] = str(i)
         msg.attach(  MIMEText(html, 'html') )
         server = smtplib.SMTP('host_name', smtp_port)  # ssl://host_name   for ssl or port 465
         server.login(user , smtp_pass)
         server.sendmail([email protected], str(i), msg.as_string())
         print ("email ::" + str(i) )
         print("Somting not good ")
 if __name__ == "__main__":  # confirms that the code is under main function
     t0 = time.time()
     len_email = len(email_s)
     i1 = 0
     while i1 < len_email : 
         y = i1 
         i1 = int(y + 60 )
         procs = []
     # instantiating process with arguments
         for i in email_s[y:i1]:  
             # print(name)
             proc = Process(target=func, args=(i,))
         # complete the processes
         for proc in procs:
     t1 = time.time()      
     total = t1-t0
     print(str(total) + " sec done") 

This Post Has 2 Comments

  1. How to use this … Code.. please post video bro

    1. Please check code now

Leave a Reply