# pip3.7 install fastapi uvicorn 安装 # uvicorn sendmail:app --reload --port 8888 --host 0.0.0.0 启动
#vim sendmail.py # -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from email.header import Header from fastapi import FastAPI from pydantic import BaseModel mail_host = "*******" # 设置服务器 mail_user = "********" # 用户名 mail_pass = "********" # 口令 class Item(BaseModel): Receives: list Content: str cc: list = None app = FastAPI() @app.post("/sendmail/") def send_mail(item: Item): msg = MIMEText(item.Content) msg['Subject'] = Header("区块链系统v1.0上线通知","utf-8") msg['From'] = ("%s<admin@*****.com>") % (Header("集团区块链项目部","utf-8"),) msg['To'] = ",".join(item.Receives) try: server = smtplib.SMTP() server.connect(mail_host) server.login(mail_user, mail_pass)s server.sendmail(msg['From'], item.Receives, msg.as_string()) server.close() return True except Exception as e: print(str(e)) return str(e)