#! /usr/bin/env python
# -*- coding: UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
mailto_list=['xxxxxxx@qq.com']#收件人(列表)
mail_host="smtp.163.com"#使用的邮箱的smtp服务器地址,这里是163的smtp地址
mail_user="xxxxxx@163.com"#用户名(网易邮箱登录的用户名)
mail_pass="xxxxxx"#密码(注意:此处密码为网易邮箱授权码,获取方式看下图)
def send_mail(to_list,sub,content):
me="你好啊"+"<"+mail_user+">"
msg = MIMEText(content,_subtype='plain')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)#将收件人列表以‘;’分隔
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception as e:
print('未知错误')
return False
for i in range(1):
if send_mail(mailto_list,"你好","python邮件发送成功了666"):
print ("发送成功!");
else:
print ("发送失败!");
然后执行python,如果收到邮件,那么恭喜你