-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail.py
executable file
·41 lines (33 loc) · 947 Bytes
/
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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
import sys
import time
from email.mime.text import MIMEText
def sendmailBcc(frm, toList, contentFile):
fp = open(contentFile, 'r')
msg = MIMEText(fp.read())
msg['Subject'] = 'Bye'
msg['From'] = frm
msg['To'] = frm
toAddr = [frm]+toList
s = smtplib.SMTP('localhost')
# print frm, '===\n', toAddr, '===\n', msg.as_string()
s.sendmail(frm, toAddr, msg.as_string())
s.quit()
if __name__ == '__main__':
if len(sys.argv) < 4:
print 'usage: ./sendmail.py from emailListFile contentFile'
exit(0)
# the format of emailListFile is something like
emails = open(sys.argv[2], 'r').readlines()
emails = map((lambda x: x.rstrip()), emails) # trim the trailing \n
start = 0
while start < len(emails):
interval = emails[start:start+10]
sendmailBcc(sys.argv[1], interval, sys.argv[3])
start = start+10
time.sleep(5)