我正在寻找用 Python 发送大量邮件(数十万封邮件)的解决方案。我有一个收件人列表(在一个文件中),我想向所有收件人发送邮件。我希望每个收件人都显示为邮件标题中的收件人,而不是密件抄送或抄送。好吧,我的解决方案:向他们每个人发送单独的邮件,而不是向所有列表发送邮件。我在下面做了一些工作:(我使用了smtplib,线程):
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 = "me@mail.test"
subject = "hello"
message = "Hello Hello"
for line in f.readlines():
t = SendMail(from, line, subject, message)
t.run()
f.close()
它工作但很慢(大约 6 封邮件/秒)。所以请帮助我让它更快。或者建议我另一种解决方案来完成这项工作。非常感谢你!