我有一个Flask服务器。在route.py中,我有这样的功能:
from flask_mail import Mail
app = flask.Flask(__name__, static_folder='static')
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'source@gmail.com'
app.config['MAIL_PASSWORD'] = 'password.'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail= Mail(app)我想使用flask_mail.Message()和mail.send在另一个脚本中的函数中发送邮件,我该怎么做?
发布于 2021-02-13 01:33:11
看一下这个例子:
email.py
from flask_mail import Message
from app import mail
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)来源:https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-x-email-support
(关于flask的一般教程)
https://stackoverflow.com/questions/66174621
复制相似问题