forked from wangwangit/python_sign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMail.py
41 lines (34 loc) · 1.05 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
import random
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import requests
from bs4 import BeautifulSoup
# 发送者邮件
sender = '[email protected]'
# 邮件内容
content = '我最帅'
# 邮件标题
title = '我最帅'
# 在邮箱网站申请授权码,不是自己的登录密码
secret = 'xxx'
def send(receiver):
smtpObj = smtplib.SMTP('smtp.qq.com', 25)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login(sender, secret)
# 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
message = MIMEText(content, 'plain', 'utf-8')
message['Subject'] = Header(title, 'utf-8')
smtpObj.sendmail(sender, receiver, message.as_string())
smtpObj.quit()
# 读取文件,获取收件人,每行填写一个邮箱!
def readMail():
resp = ''
with open('mail.txt', 'r') as f:
receiverList = f.read().splitlines()
for receiver in receiverList:
resp += receiver + ','
return resp[0:-1]
if __name__ == '__main__':
send(readMail())