首页 > 其他 > 详细

使用QQ邮箱发送邮件并添加附件

时间:2018-12-05 19:27:16      阅读:241      评论:0      收藏:0      [点我收藏+]
def send_email(str):
fromaddr = ‘xxxxxxxxx@qq.com‘ # 发送方邮箱
password = ‘xxxxxxxxx‘ # 填入发送方邮箱的授权码
toaddrs = [str] # 收件人邮箱

content = ‘最新生成内容‘
textApart = MIMEText(content)

zipFile = file_dir + ‘/aa_file.zip‘
zipApart = MIMEApplication(open(zipFile, ‘rb‘).read())
zipApart.add_header(‘Content-Disposition‘, ‘attachment‘, filename=‘QianBi.zip‘)

m = MIMEMultipart()
m.attach(textApart)
m.attach(zipApart)
m[‘Subject‘] = ‘千币分析‘

try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 邮件服务器及端口号
s.login(fromaddr, password)
s.sendmail(fromaddr, toaddrs, m.as_string())
print(‘success‘)
s.quit()
except smtplib.SMTPException as e:
print(‘error:‘, e)

if __name__ == ‘__main__‘:
send_email()

使用QQ邮箱发送邮件并添加附件

原文:https://www.cnblogs.com/ioswws/p/10072383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!