💩 写了依托smtp
This commit is contained in:
1 parent
2da504cdc4
commit
a3c361e591
4 files changed
+80
No files matched your search
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")" || exit
|
||||
source ./.env/bin/activate
|
||||
#exec ./smtp.bin
|
||||
exec python3 smtp.py
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")" || exit
|
||||
python3 -m venv .env
|
||||
#sudo chmod +x .env/bin/activate
|
||||
source .env/bin/activate
|
||||
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
#nuitka --standalone smtp.py
|
||||
@@ -0,0 +1,6 @@
|
||||
nuitka
|
||||
flask
|
||||
flask-cors
|
||||
flask_sqlalchemy
|
||||
#gunicorn
|
||||
waitress
|
||||
@@ -0,0 +1,62 @@
|
||||
from flask import Flask,app
|
||||
from urllib import request
|
||||
from email.mime.text import MIMEText
|
||||
from email.header import Header
|
||||
import smtplib
|
||||
import random
|
||||
from waitress import serve
|
||||
|
||||
verification_code = 0
|
||||
|
||||
@app.route('/send_email', methods=["POST"])
|
||||
|
||||
def send_email():
|
||||
data = request.get_json()
|
||||
|
||||
reciver_email = data.get('email')
|
||||
SMTP_SERVER = ''
|
||||
SMTP_PORT = 587
|
||||
SENDER_EMAIL = ''
|
||||
__PASS = ''
|
||||
|
||||
verification_code = random.randint(1000,9999)
|
||||
|
||||
subject = "DNFS 验证码"
|
||||
content = f"DNFS: 您的验证码为{str(verification_code)}"
|
||||
|
||||
email_message = MIMEText(content, 'plain', 'utf-8')
|
||||
email_message['From'] = Header(SENDER_EMAIL, 'utf-8')
|
||||
email_message['To'] = Header(reciver_email, 'utf-8')
|
||||
email_message['Subject'] = Header(subject)
|
||||
|
||||
try:
|
||||
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
||||
server.starttls()
|
||||
server.login(SENDER_EMAIL, __PASS)
|
||||
server.sendmail(SENDER_EMAIL, [reciver_email], email_message.as_string())
|
||||
return 200
|
||||
|
||||
except Exception as err:
|
||||
raise err
|
||||
return 400
|
||||
|
||||
finally:
|
||||
server.quit()
|
||||
|
||||
@app.route('/get_verification_code', method=["POST"])
|
||||
|
||||
def get_verification_code():
|
||||
data=request.get_json()
|
||||
|
||||
input_verification_code = data.get('verification_code')
|
||||
|
||||
if verification_code == input_verification_code:
|
||||
return 200
|
||||
else:
|
||||
return 400
|
||||
|
||||
ADDR = '127.0.0.1'
|
||||
PORT = 8007
|
||||
if __name__ == "__main__":
|
||||
print(f'Listen at http://{ADDR}:{PORT}')
|
||||
serve(app, host=ADDR, port=PORT)
|
||||
Reference in new issue
Block a user