用python 写了一个可以发送邮件的小程序
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
# 创建SMTP服务器对象
server = SMTP('smtp.163.com')
user = 'xxxxxxx@163.com'
password = '*********'
# 创建连接
server.login(user, password)
# 邮件发送内容类型
message = MIMEMultipart()
# 发送人
message['from'] = 'xxxxxxxx@163.com'
# 接收者
message['to'] = 'xxxxxxxxx@qq.com'
# 主题
message['subject'] = 'python 爱好者'
# html 附件
html = '<p>图片附件</p> <img src="cid:imageid">'
msg = MIMEText(html, 'html')
message.attach(msg)
# 图片附件
with open('timg.jpg', 'rb') as file:
msgimage = MIMEImage(file.read())
msgimage.add_header("Content-ID", "imageid")
message.attach(msgimage)
# 文件附件
with open('demo2.py', 'rb') as file:
msgfile = MIMEText(file.read(), "base64", 'utf-8')
msgfile['Content_Type'] = 'application/octet-stream'
msgfile['Content-Disposition'] = "attachment ; filename = 'test.py'"
message.attach(msgfile)
server.sendmail(user, '1104056609@qq.com', message.as_string())
# 关闭连接
server.quit()