import smtplib
from email.mime.text
import MIMEText
from email.mime.multipart
import MIMEMultipart
username=
'fasongren_mail@163.com' #发送方邮件地址
email_host =
'smtp.163.com' #邮件服务器地址
passwd=
'woshinige123' #发送方邮件授权给第三方的登录密码
recv=
'88888888@qq.com,66666666@qq.com' #接收方邮件地址
title=
'邮件标题' #邮件标题
content=
'发送邮件测试' #邮件内容
msg =
MIMEMultipart()
file=
'url编码.py' #附件的文件名
att = MIMEText(open(file,encoding=
'utf-8').read())
#构建一个附件的U对象
att[
"Content-Type"] =
'application/octet-stream'
att["Content-Disposition"] =
'attachment; filename="%s"'%file
#这个是在邮件中显示的附件名
msg.attach(att)
#把刚才创建好的附件,加到正文里面
msg.attach(MIMEText(
'邮件的内容。。。。'))
#写邮件内容
msg[
'Subject'] = title
# 邮件主题
msg[
'From'] = username
# 发送者账号
msg[
'To'] = recv
# 接收者账号列表
# smtp = smtplib.SMTP_SSL(email_host,port=465)#发送方邮箱是qq邮箱
smtp = smtplib.SMTP(email_host,port=25)
#其他邮箱
smtp.login(username,passwd)
smtp.sendmail(username,recv,msg.as_string())
smtp.quit()
转载于:https://www.cnblogs.com/lincy/p/8490469.html