開啓163的smtp服務器(綁定自己的手機)
163郵箱地址:https://mail.163.com/
記住自己的SMTP服務器
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()