import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
'''邮箱服务器ip'''
smtpserver = 'smtp.163.com'
'''账号密码'''
user = 'xxxxxx@163.com'
passwd = 'xxxxxx'
'''发送和接收'''
sender = 'xxxxxx@163.com'
receives = ['xxxxxx@163.com', 'xxxxxx@qq.com']
'''邮件标题'''
subject = 'xxxxxx 图片上传'
content = '<html><h1 style="color:red">xxxxxx</h1></html>'
'''构建附件内容'''
file_dir = open(r'F:\360MoveData\Users\PVer\Desktop\xxx.jpg', 'rb').read()
att = MIMEText(file_dir, 'base64', 'utf-8')
att['Content-Type'] = 'application/octet-stream'
att['Content-Disposition'] = 'attachment;filename="xxx.jpg"'
'''构建发送与接收信息'''
msgRoot = MIMEMultipart()
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
'''邮件内容'''
msgRoot['subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ','.join(receives)
msgRoot.attach(att)
'''ssl端口'''
smtp = smtplib.SMTP_SSL(smtpserver, 465)
smtp.helo(smtpserver)
smtp.ehlo(smtpserver)
smtp.login(user, passwd)
smtp.sendmail(sender, receives, msgRoot.as_string())
smtp.quit()
07-19
802
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交