-
Notifications
You must be signed in to change notification settings - Fork 3
/
sendmail.py
162 lines (95 loc) · 3.66 KB
/
sendmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# -*- coding: utf-8 -*-
import time
import smtplib
import pymongo
import argparse
from email.mime.text import MIMEText
addr = "localhost" # "smtp.gmail.com"
port = 25 # 587
morf = "[email protected]"
subject = "A Request for Twitter Screen Name and Facebook Homepage URL"
content = """
Dear %s,
<p>This is a letter from MrUirf team.</p>
<p>We started a project, to infuse netizens' Twitter tweets, Facebook statuses and GitHub repo. And here is our repository link: https://github.com/stamaimer/MrUirf.</p>
<p><b>And we need your help, supplying us your Twitter , Facebook and GitHub id ( or username ).</b></p>
<p>Your tweets, statuses and repos info will be used to:</p>
<ol>
<li>entity recognition & relation words extraction.</li>
<li>tweets & statuses similarity calculation.</li>
<li>generate social graph.</li>
</ol>
<p><b>* and we will never leak your info to other people or organisations.</b></p>
<p><b>Please reply your info in json format:</b></p>
<p>ex. {"github":"curme", "facebook":"https://www.facebook.com/hui.zhan.796", "twitter":"curmium"}</p>
<ol>
<li>github: your "login"(the second line below your avatar)</li>
<li>facebook: your homepage url</li>
<li>twitter: screen name ( ps. screen name is the name that your friends use to @ you. ex. '@curmium')</li>
</ol>
<p>If you have no Twitter or Facebook accounts, please ignore this letter.</p>
<p>Thank you for reading this letter. Your support are really meaningful to us!</p>
<p>Thank you gratefully!</p>
Sincerely,
MrUirf.
"""
# def sendmail(usr, psd, morf, tolist):
def sendmail(tolist):
log = open("log", 'w')
try:
server = smtplib.SMTP(addr, port)
# server.ehlo()
# server.starttls()
# server.ehlo()
# server.login(usr, psd)
for to in tolist:
msg = MIMEText(content % to["login"], 'html')
msg["From"] = morf
msg["To"] = to["email"]
msg["Subject"] = subject
try:
server.sendmail(morf, [to["email"]], msg.as_string())
print "successfully sent email to %s, addr: %s" % (to["login"], to["email"])
log.write("successfully sent email to %s, addr: %s\n" % (to["login"], to["email"]))
time.sleep(300)
except:
print "failed to send email to %s, addr: %s" % (to["login"], to["email"])
log.write("failed to send email to %s, addr: %s\n" % (to["login"], to["email"]))
continue
server.close()
print "successfully sent the mail..."
except:
print "failed to send mail..."
finally:
log.close()
def get_user_list():
mongo_client = pymongo.MongoClient('127.0.0.1', 27017)
msif = mongo_client.msif
github_users = msif.github_users
items = github_users.find({}, {"login":1, "email":1, "_id":0})
items = [ {"login":item["login"], "email":item["email"]} \
for item in items \
if item.has_key("email") \
and item["email"] != None \
and item["email"] != '' ]
# items = reversed(items)
# seeds = open("GithubUsersEmails.json", 'w')
# for item in items:
# seeds.write(str(item))
# seeds.write("\n")
# seeds.close()
return items
if __name__ == '__main__':
# argument_parser = argparse.ArgumentParser(description="")
# argument_parser.add_argument("usr", help="")
# argument_parser.add_argument("psd", help="")
# args = argument_parser.parse_args()
# usr = args.usr
# psd = args.psd
user_list = get_user_list()
# user_list = [{"login":"stamaimer", "email":"[email protected]"},
# {"login":"stamaimer", "email":"[email protected]"},
# {"login":"curmium", "email":"[email protected]"},
# {"login":"yaohu", "email":"[email protected]"}]
# sendmail(usr, psd, usr, user_list)
sendmail(user_list)