开始入几个模块smtplib、email

import smtplib

from email.mime.text import MIMEText

# 发送邮件因变量

def send_mail():

try:

e_mail = smtplib.SMTP_SSL('smtp.163.com', 994) # (域名,端标语)

e_mail.login('XXX@163.com', '***') # (发送邮箱,邮箱的受权码[简直见下图])

msg = "这边是要发送的文本实质"

msg = MIMEText(msg, "plain", 'utf-8')

msg['Subject'] = '用Python发的' # 邮件的题目

msg['From'] = 'XXX@163.com' # 发送人邮箱

msg['To'] = 'XXX@qq.com' # 收件人邮箱

e_mail.sendmail('XXX@163.com', ['XXX@qq.com'], msg.as_string())

# (发送人邮箱,收件人邮箱【可为列表】,字符串情势文本实质)

e_mail.close()

print("发送胜利")

return 1

except Exception as msg:

print("发送波折", msg)

return 0

if __name__ == "__main__":

send_mail() # 挪用发送因变量