本文共 657 字,大约阅读时间需要 2 分钟。
使用126邮箱发送邮件的python脚本:
注:
1、密码处是126邮箱的授权码,非登录密码#!/usr/bin/python
#coding=utf-8import smtplib
from email.mime.text import MIMETextsender='yangming@126.com'
spass='xxxxxx'
receiver='zhi.yang@ming.com'
def mail():
ret=Truetry:context = "aa"msg=MIMEText(context,'plain','utf-8')msg['From']=sendermsg['To']=receivermsg['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 = Falseprint(e)return retret = mail()
if ret:print("邮件发送成功")else:print("邮件发送失败"):wq转载于:https://blog.51cto.com/yangzhiming/2125566