forked from queensun/Nyspider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendemail.py
29 lines (26 loc) · 1.11 KB
/
sendemail.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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import time
def sendmail():
sender = '[email protected]'
receivers = ['[email protected]'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
#创建一个带附件的实例
message = MIMEMultipart()
message['From'] = Header("xxxx", 'utf-8')
message['To'] = Header("[email protected]", 'utf-8')
subject ='time.strftime("%Y-%m-%d %H:%M:%S")'
message['Subject'] = Header(subject, 'utf-8')
#邮件正文内容
message.attach(MIMEText('time.strftime("%Y-%m-%d %H:%M:%S")', 'plain', 'utf-8'))
att1 = MIMEText(open('result.xls', 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att1["Content-Disposition"] = 'attachment; filename="result.xls"'
message.attach(att1)
server=smtplib.SMTP_SSL('smtp.qq.com')
server.ehlo('smtp.qq.com')
server.login(sender,passwd)
server.sendmail(sender, receivers, message.as_string())
sendmail()