python auto send email利用python自动发送邮件或把nmap扫描结果发送到邮箱-泓源视野

python auto send email利用python自动发送邮件或把nmap扫描结果发送到邮箱

version1.1   auto_send_email.py

#!-- coding: utf-8 --
#send ok but only same 163email adresse
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import json
#邮件发送类
class EmailManager:
def __init__(self,user,psw,sender):
self.user = user
self.psw = psw
self.sender = sender
self.host = "smtp.163.com"
def sendEmail(self,receivers,content,title):
message = MIMEText(content,'plain','utf-8')
message['From'] = "{}".format(self.sender)
message['To'] = ",".join(receivers)
message['Subject'] = title
try:
smtpObj = smtplib.SMTP_SSL(self.host,465)
smtpObj.login(self.user,self.psw)
smtpObj.sendmail(self.sender,receivers,message.as_string())
print("mail sender successfully!")
except smtplib.SMTPException as e:
print(e)
if __name__ == "__main__":
with open("send_email_config.json","r") as f:
jsonstr = json.load(f)
EmailManager = EmailManager(jsonstr["user"],jsonstr["psw"],jsonstr["sender"])
EmailManager.sendEmail(["[email protected]"],"from yann message","message bla bla")

下面是发送邮件的json配置文件
send_email_config.json

{
"user": "[email protected]",
"psw": "XxxxxAxxxGxxxxCQ",
"sender": "[email protected]"
}

配置163邮箱的smtp的授权码和发送者邮件


version 2  code  for demande

python auto send email利用python自动发送邮件或把nmap扫描结果发送到邮箱插图

本文由 泓源视野 作者:admin 发表,其版权均为 泓源视野 所有,文章内容系作者个人观点,不代表 泓源视野 对观点赞同或支持。如需转载,请注明文章来源。
8

发表评论

Protected with IP Blacklist CloudIP Blacklist Cloud
您是第8237895 位访客, 您的IP是:[3.236.86.184]