增加邮箱功能
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
from flask_mail import Message
|
||||||
|
|
||||||
|
from applications.extensions.init_mail import mail
|
||||||
|
|
||||||
|
|
||||||
|
# send_mail(subject='title', recipients=['123@qq.com'], content='body')
|
||||||
|
def send_mail(subject, recipients, content):
|
||||||
|
try:
|
||||||
|
message = Message(subject=subject, recipients=recipients, body=content)
|
||||||
|
mail.send(message)
|
||||||
|
except Exception as e:
|
||||||
|
print('邮箱发送出错了')
|
||||||
|
raise
|
||||||
@@ -22,6 +22,15 @@ class BaseConfig:
|
|||||||
SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
|
SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
|
||||||
# 默认日志等级
|
# 默认日志等级
|
||||||
LOG_LEVEL = logging.WARN
|
LOG_LEVEL = logging.WARN
|
||||||
|
#
|
||||||
|
MAIL_SERVER = os.getenv('MAIL_SERVER') or 'smtp.qq.com'
|
||||||
|
MAIL_USE_TLS = False
|
||||||
|
MAIL_USE_SSL = True
|
||||||
|
MAIL_PORT = 465
|
||||||
|
MAIL_USERNAME = os.getenv('MAIL_USERNAME') or '123@qq.com'
|
||||||
|
MAIL_PASSWORD = os.getenv('MAIL_PASSWORD') or 'XXXXX' # 生成的授权码
|
||||||
|
# 默认发件人的邮箱,这里填写和MAIL_USERNAME一致即可
|
||||||
|
MAIL_DEFAULT_SENDER = ('pear admin', os.getenv('MAIL_USERNAME') or '123@qq.com')
|
||||||
|
|
||||||
|
|
||||||
class TestingConfig(BaseConfig):
|
class TestingConfig(BaseConfig):
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from .init_login import init_login_manager
|
|||||||
from .init_debug_tool import init_debug_tool
|
from .init_debug_tool import init_debug_tool
|
||||||
from .init_template_directives import init_template_directives
|
from .init_template_directives import init_template_directives
|
||||||
from .init_error_views import init_error_views
|
from .init_error_views import init_error_views
|
||||||
|
from .init_mail import init_mail
|
||||||
|
|
||||||
|
|
||||||
def init_plugs(app: Flask) -> None:
|
def init_plugs(app: Flask) -> None:
|
||||||
@@ -13,3 +14,4 @@ def init_plugs(app: Flask) -> None:
|
|||||||
init_databases(app)
|
init_databases(app)
|
||||||
init_template_directives(app)
|
init_template_directives(app)
|
||||||
init_error_views(app)
|
init_error_views(app)
|
||||||
|
init_mail(app)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from flask import Flask
|
||||||
|
from flask_mail import Mail
|
||||||
|
|
||||||
|
mail = Mail()
|
||||||
|
|
||||||
|
|
||||||
|
def init_mail(app: Flask):
|
||||||
|
mail.init_app(app)
|
||||||
Reference in New Issue
Block a user