'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.小結
通過上面的代碼,想必大家已經對發(fā)郵件有了基本的認識。
從整體上我們要把握整個過程的思路:
登錄
寫郵件
發(fā)送
微觀上我們需要了解:
smtplib/email 模塊的代碼規(guī)則;
什么時候使用 SMTP,什么時候使用 SMTP_SSL?
5/6 首頁 上一頁 3 4 5 6 下一頁 尾頁