使用126邮箱发送邮件的python脚本:

注: 1、密码处是126邮箱的授权码,非登录密码

vi mail.py

#!/usr/bin/python #coding=utf-8

import smtplib from email.mime.text import MIMEText

sender='yangming@126.com'

spass='xxxxxx'

receiver='zhi.yang@ming.com'

def mail(): ret=True try: context = "aa" msg=MIMEText(context,'plain','utf-8') msg['From']=sender msg['To']=receiver msg['Subject']="aaaaa" server=smtplib.SMTP("smtp.126.com") server.login(sender,spass) server.sendmail(sender,receiver,msg.as_string()) server.quit() except Exception as e: ret = False print(e) return ret

ret = mail() if ret: print("邮件发送成功") else: print("邮件发送失败") :wq

python mail.py