/
customer_email.py
189 lines (145 loc) · 4.62 KB
/
customer_email.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#coding=utf-8
###send email from custom domain
###
###
import smtplib
import time, traceback, sys, os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from pymongo import MongoClient
import logging
import multiprocessing
import random
from email.utils import formatdate
content = '''hi,\n
I sent you email yesterday , did you get it? Its very important anyway.Reply me back to confirm that you already got this email.\n
The email is about \n
\n
\n
\n
Sent from my iPhone
'''
content1 = '''hi,\n
I sent you email few days ago , did you get it?.Reply me back to confirm that you already got this email.\n
The email is about \n
\n
\n
\n
Sent from my iPhone
'''
content2 = '''hello,\n
I sent you email last week ago , did you get it?.Reply me back to confirm that you already got this email.\n
It is about \n
\n
\n
\n
Sent from my iPhone
'''
content3 = '''hi,\n
I sent you email last week , did you get it?.It's important.Reply me back to confirm that you already got this email.\n
It is about \n
\n
\n
\n
Sent from my iPhone
'''
content4 = '''hi,\n
I sent you email yesterday , did you get it?.It's important.Reply me back to confirm that you already got this email.\n
This email is about \n
\n
\n
\n
Sent from my iPhone
'''
f = open("t5_2.html",'r')
html_content = f.read()
f.close()
send_from = "kate@gameandroid.info"
MONGO_HOST = '127.0.0.1'
MONGO_PORT = 27017
MONGO_DB = 'txt'
MONGO_USER_COLL = 'email'
MONGO = MongoClient(MONGO_HOST,MONGO_PORT)
def send_mail(mail_from, password, mail_to, subject, content):
handle = smtplib.SMTP('mail.gameandroid.info', 25)
handle.ehlo()
handle.starttls()
handle.login(mail_from, password)
msg = MIMEMultipart()
msg["From"] = send_from
msg["To"] = mail_to
msg["Subject"] = subject
msg["Date"] = formatdate(localtime=True)
msg.attach(MIMEText(content, 'plain'))
handle.sendmail(send_from, mail_to, msg.as_string())
handle.close()
if not MONGO[MONGO_DB][MONGO_USER_COLL].find_one({'_id':mail_to}):
MONGO[MONGO_DB][MONGO_USER_COLL].insert_one({'_id':mail_to})
print ("Email send")
def send_html(mail_from, password, mail_to, subject, content):
handle = smtplib.SMTP('mail.gameandroid.info', 25)
handle.ehlo()
handle.starttls()
handle.login(mail_from, password)
msg = MIMEMultipart('alternative')
msg["From"] = send_from
msg["To"] = mail_to
msg["Subject"] = subject
msg["Date"] = formatdate(localtime=True)
msg.attach(MIMEText(content, 'html'))
handle.sendmail(send_from, mail_to, msg.as_string())
handle.close()
if not MONGO[MONGO_DB][MONGO_USER_COLL].find_one({'_id':mail_to}):
MONGO[MONGO_DB][MONGO_USER_COLL].insert_one({'_id':mail_to})
print ("Email send")
def split_list(lines):
global content
num = 0
for line in lines:
line = line.strip()
if not (line.find("@") != -1):
continue
if MONGO[MONGO_DB][MONGO_USER_COLL].find_one({'_id': line}):
continue
line_list = line.split("@")
username,mailserver = line_list[0],line_list[1]
#if mailserver in ["aol.com"]:
# continue
if username.find(".") != -1:
username = username.split(".")[0]
#d[mailserver] = d.get(mailserver,0)+1
content = random.choice([content,content1,content2,content3,content4])
#content = content.format(name=username)
#html_content = html_content
print ("Email send to %s" % line)
#html_content = html_content
send_mail('kate', 'password123',line, 'Hi ', content)
num = num +1
rtime = random.randomint(240,400)
time.sleep(rtime)
if __name__ == '__main__':
num = 0
lines = [line.rstrip('\n') for line in open('F://500px_photos-master//contacts_0610.csv')]
lines = lines[7542:]
d = {}
clean_email = []
for line in lines:
line = line.strip()
if MONGO[MONGO_DB][MONGO_USER_COLL].find_one({'_id': line}):
continue
mail = line.split("@")[1].strip()
d[mail] = d.get(mail, 0) + 1
clean_email.append(line)
l = []
for k,v in d.items():
#if v>100:
l.append(k.strip())
process_list = []
print len(l)
for mail in l:
split_mail = [line for line in clean_email if line.split("@")[1].strip() == mail.strip()]
#print split_mail
p = multiprocessing.Process(target=split_list, args=(split_mail,))
process_list.append(p)
for process in process_list:
process.start()