我想知道这是不是最好的方法,但是Flask-Mail扩展接受一些SMTP服务器配置,并在任何时候发送电子邮件时调用Mail类的send函数。
我正在使用SMTP提供程序,并编写了自己的发送函数,该函数利用了Flask-Mail扩展的Message对象,现在我想修补邮件对象以使用此自定义函数。
我尝试过以下几种方法:
from flask_mail import Mail
#override the send email to use
#the elastic email
Mail.send = _custom_send
app = Flask(__name__)
mail = Mail()
mail.init_app(app)和
app = Flask(__name__)
mail = Mail()
mail.send = types.MethodType(_custom_send, mail)
mail.init_app(app)但是,Mail类的现有send函数仍在被调用。
有什么想法吗?
发布于 2014-04-07 01:45:44
关于你的第一句话
我在想这是不是最好的方法
为什么不直接继承原来的Mail类并重新定义.send呢
class MyMail(Mail):
def send(self, ...):
....https://stackoverflow.com/questions/22897534
复制相似问题