I'm looking of solutions to send huge number of mails (hundreds of thousands) in Python. I have a list of recipients (in a file), and I want to send a mail to all of them. I want each of recipients was show as receiver in mail header, not bcc or cc. Well, my solutions: send a separated mail to each of them not a mail to all list. I did some works below:(I used smtplib, threading):
class SendMail(threading.Thread): def __init__(self, from, to, subject, message): self.from = from self.to = to self.subject = subject self.message = message def run(self): try: msg = MIMEMultipart('alternative') msg['Subject'] = self.subject msg['From'] = self.from msg['To'] = self.to msg.attach(MIMEText(self.message , 'html')) server = smtplib.SMTP() server.connect('xxxxx', 25) server.login('cxxxxx', 'yyyyyy') server.sendmail(self.from, self.to, msg.as_string()) except: pass def sendmail(): f = open('recipients','w') from = "email@example.com" subject = "hello" message = "Hello Hello" for line in f.readlines(): t = SendMail(from, line, subject, message) t.run() f.close()
It work but very slow (about 6 mails/second). So please help me to make it faster. Or suggest me another solutions to do this job. Thank you very much!