import smtplib
from email.mime.text import mimetext
from email.mime.image import mimeimage
from email.mime.multipart import mimemultipart #多**處理模組
from email.header import header
mail_host =
"smtp.qq.com"
mail_user =
mail_pass =
"*******"
#授權碼
sender =
receiver =
]textcontent = mimetext(
'這個郵件裡面展示了我用四行**給加乙個濾鏡的功能'
,'plain'
,'utf-8'
)textcontent[
'from'
]= header(
"夜曲程式設計"
,'utf-8'
)textcontent[
'to'
]= header(
"測試"
,'utf-8'
)imagefile =
'.//image'
imageattachment = mimeimage(
open
(imagefile,
'rb'
).read(),
'jpeg'
)imageattachment.add_header(
'content-disposition'
,'attachment'
,filename=imagefile)
imagefile2 =
'郭麒麟.jpg'
imageattachment2 = mimeimage(
open
(imagefile2,
'rb'
).read(),
'jpeg'
)imageattachment2.add_header(
'content-disposition'
,'attachment'
,filename=imagefile2)
message = mimemultipart(
)message.attach(textcontent)
message.attach(imageattachment)
message.attach(imageattachment2)
subject =
'夜曲程式設計pythonsmtp郵件測試'
message[
'subject'
]= header(subject,
'utf-8'
)smtpobj = smtplib.smtp_ssl(mail_host)
smtpobj.connect(mail_host,
465)
smtpobj.login(mail_user,mail_pass)
smtpobj.sendmail(sender,receiver,message.as_string())
print
("傳送郵件成功"
)
使用python傳送郵件
傳送郵件這個功能非常實用,比如你寫了乙個爬蟲,可以通過郵件來接收程式異常或者任務完成的通知,再比如你搭了乙個 別人只需留下他的郵箱,你就可以自動給他傳送郵件。總之我覺得郵件通知非常適合那些處理批量 大量任務,你可以不用守在電腦前等待處理結果,在程式裡配置好郵件通知後,只需留意郵箱通知就好了。在 py...
學習使用python傳送郵件
使用python傳送郵件 import os import smtplib import mimetypes from email.mimemultipart import mimemultipart from email.mimebase import mimebase from email.mi...
使用python指令碼傳送郵件
import smtplib from email.mime.text import mimetext from email.header import header 傳送方 sender 163.com 接收方 receiver 163.com 中文需要utf 8引數,不好使需要調整 在這裡輸入郵...