# 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)

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

open