Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python批量发送邮件
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import urllib2, time, string, random
email = ''
title = raw_input("输入邮件标题:")
if len(title) <= 0:
title = '标题'
pass
content = raw_input("输入邮件内容:")
if len(content) <= 0:
content = '内容'
pass
f = open("mail.txt") # 返回一个文件对象
email = f.readline() # 调用文件的 readline()方法
email = email.strip()
while email:
rdstr = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10))
url = 'http://192.168.0.52/sendmail/'+email+'/'+title+'/'+content+' '+rdstr
print url
resp = ''
try:
resp = urllib2.urlopen(url)
except Exception as e:
email = f.readline()
email = email.strip()
continue
raise
else:
pass
finally:
pass
print email+ ' send ' +resp.read()
time.sleep(50)
email = f.readline()
email = email.strip()
f.close()
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.