天天看點

python使用163郵箱發送郵件

開啟163的smtp伺服器(綁定自己的手機)

163郵箱位址:https://mail.163.com/

python使用163郵箱發送郵件

記住自己的SMTP伺服器

python使用163郵箱發送郵件
python使用163郵箱發送郵件

 Smtp伺服器位址 和 端口

Ssl: smtp.163.com:465

非ssl : smtp.163.com:25

#coding:utf -8

import smtplib #smtp伺服器
from email.mime.text import MIMEText #郵件文本

#郵件建構

subject = "滴滴答答"#郵件标題
sender = "*********@163.com"#發送方
content = "新年快樂!"
recver = "*******@qq.com"#接收方
password = "*****"郵箱密碼
message = MIMEText(content,"plain","utf-8")
#content 發送内容     "plain"文本格式   utf-8 編碼格式

message['Subject'] = subject #郵件标題
message['To'] = recver #收件人
message['From'] = sender #發件人

smtp = smtplib.SMTP_SSL("smtp.163.com",994) #執行個體化smtp伺服器
smtp.login(sender,password)#發件人登入
smtp.sendmail(sender,[recver],message.as_string()) #as_string 對 message 的消息進行了封裝
smtp.close()
           

繼續閱讀