-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmail.py
More file actions
48 lines (38 loc) · 1.06 KB
/
mail.py
File metadata and controls
48 lines (38 loc) · 1.06 KB
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
#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import threading
def send_mail(thread_id):
subject = 'Hi, benbenben'
mail_body = 'Hi, test! %s' % thread_id
password = 'xxx_sasa'
message = MIMEMultipart()
# message['From'] = sender
# message['To'] = receiver
message['From'] = ''
message['To'] = ''
message['Subject'] = Header(subject, 'utf-8')
message.attach(MIMEText(mail_body, 'plain', 'utf-8'))
smtp = smtplib.SMTP()
smtp.connect('smtp.sina.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, message.as_string())
smtp.quit()
def main():
process_num = 2
threads = []
for i in range(process_num):
thread = threading.Thread(target = send_mail, args = (i, ))
threads.append(thread)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
if __name__ == "__main__":
main()