'utf-8')part2[
'Content-Type'] =
'application/octet-stream'part2[
'Content-Disposition'] =
'attachment;filename="abc.txt"'with open(
'1.png',
'rb')
as fp: picture = MIMEImage(fp.read()) picture[
'Content-Type'] =
'application/octet-stream' picture[
'Content-Disposition'] =
'attachment;filename="1.png"'message.attach(part1)message.attach(part2)message.attach(picture)
try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host,
25) smtpObj.login(mail_user,mail_pass) smtpObj.sendmail( sender,receivers,message.as_string()) print(
'success') smtpObj.quit()
except smtplib.SMTPException
as e: print(
'error',e)
6.小结
通过上面的代码,想必大家已经对发邮件有了基本的认识。
从整体上我们要把握整个过程的思路:
登录
写邮件
发送
微观上我们需要了解: