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

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

version1.1   auto_send_email.py

  1. #!-- coding: utf-8 --
  2. #send ok but only same 163email adresse
  3. import smtplib
  4. from email.mime.text import MIMEText
  5. from email.header import Header
  6. import json
  7. #邮件发送类
  8. class EmailManager:
  9. def __init__(self,user,psw,sender):
  10. self.user = user
  11. self.psw = psw
  12. self.sender = sender
  13. self.host = "smtp.163.com"
  14. def sendEmail(self,receivers,content,title):
  15. message = MIMEText(content,'plain','utf-8')
  16. message['From'] = "{}".format(self.sender)
  17. message['To'] = ",".join(receivers)
  18. message['Subject'] = title
  19. try:
  20. smtpObj = smtplib.SMTP_SSL(self.host,465)
  21. smtpObj.login(self.user,self.psw)
  22. smtpObj.sendmail(self.sender,receivers,message.as_string())
  23. print("mail sender successfully!")
  24. except smtplib.SMTPException as e:
  25. print(e)
  26. if __name__ == "__main__":
  27. with open("send_email_config.json","r") as f:
  28. jsonstr = json.load(f)
  29. EmailManager = EmailManager(jsonstr["user"],jsonstr["psw"],jsonstr["sender"])
  30. EmailManager.sendEmail(["lvwuwei@163.com"],"from yann message","message bla bla")

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

  1. {
  2. "user": "h4ckg3h2y1@163.com",
  3. "psw": "XxxxxAxxxGxxxxCQ",
  4. "sender": "h4ckg3h2y1@163.com"
  5. }

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


version 2  code  for demande

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

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

发表评论

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