Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
# python 2.3.*: email.Utils email.Encoders
from email.utils import COMMASPACE, formatdate
from email import encoders
import random
import smtplib
import time
def send(senders, bcc):
print bcc
u1 = random.choice(senders).split(' ')
u2 = random.choice(senders).split(' ')
u1[1] = u1[1].rstrip()
mail_from = u1[0] + '@qq.com'
mail_to = [u2[0] + '@qq.com']
server = {'host': 'smtp.qq.com:25', 'user': u1[0], 'passwd': u1[1].rstrip()}
subject = '百度居然做了一款免费的加速器,兄弟们试试!'
text = '附上下载地址: http://t.cn/zQw21al<br><img src="http://image142-c.poco.cn/mypoco/myphoto/20130710/19/17392720820130710191406037.png" />'
cc = []
msg = MIMEMultipart()
msg['From'] = mail_from
msg['Subject'] = subject
msg['To'] = COMMASPACE.join(mail_to)
msg['Cc'] = COMMASPACE.join(cc)
msg['Bcc'] = COMMASPACE.join(bcc)
msg['Date'] = formatdate(localtime=True)
html_att = MIMEText(text, 'html', 'utf-8')
msg.attach(html_att)
smtp = smtplib.SMTP(server['host'])
smtp.login(server['user'], server['passwd'])
smtp.sendmail(mail_from, mail_to + cc + bcc, msg.as_string())
smtp.close()
sendMax = 5
f = open('sender', 'r')
senders = f.readlines()
f.close()
f = open('bcc', 'r')
bcc_all = f.readlines()
f.close()
bcc_all = map(lambda row: row.rstrip() + '@qq.com', bcc_all)
bcc = []
while bcc_all.__len__() > 0:
bcc.append(bcc_all.pop())
if bcc.__len__() >= sendMax:
i = 0
while True:
try:
send(senders, bcc)
break
except smtplib.SMTPException:
if i >= 5:
print 'Failed'
break
print 'Failed -> Retry'
time.sleep(1)
i += 1
bcc = []
if bcc.__len__() > 0:
i = 0
while True:
try:
send(senders, bcc)
break
except smtplib.SMTPException:
if i >= 5:
print 'Failed'
break
print 'Failed -> Retry'
time.sleep(1)
i += 1
print 'finish'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.