python发送邮件功能实现代码

本文实例为大家分享了python发邮件精简代码,供大家参考,具体内容如下

import smtplib
from email.mime.text import mimetext
from email.utils import formataddr
#发送邮件功能
def send_mail(send_message_txt,*senders_list,**send_to_people):
flag = true
try:
#编写发送的内容
send_msg = mimetext(send_message_txt,”plain”,”utf-8″)
send_msg[“from”] = formataddr([“发送人姓名”,”邮箱账号”])
#f发送人的名单
for sender_name,mail_address in send_to_people.items():
send_msg[“to”] = formataddr([sender_name,mail_address])
else:
print(“添加所有发送人”)
send_msg[“subject”] = “出现异常的sqlmap文件内容”
#登录邮箱服务器
send_server = smtplib.smtp(“smtp.126.com”,25)
send_server.login(“登录邮箱账号”,”邮箱密码”)
#发送邮件
send_server.sendmail(“zqgcy0808@126.com”,senders_list,send_msg.as_string())
send_server.quit()
except exception as e:
print(e)
flag = false
return flag

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

Posted in 未分类

发表评论