擅长:python、mysql、java
<p>在mail.py文件中,导入“app”和“mail”对象。然后,使用请求上下文。做这样的事:</p>
<pre><code>from whateverpackagename import app
from whateverpackagename import mail
@celery.task
def send_forgot_email(email, ref):
with app.test_request_context():
msg = Message("Recover your Crusade Gaming Account")
msg.recipients = [email]
msg.sender = "Crusade Gaming stuff@cg.com"
msg.html = \
"""
Hello Person,<br/>
You have requested your password be reset. <a href="{0}" >Click here recover your account</a> or copy and paste this link in to your browser: {0} <br />
If you did not request that your password be reset, please ignore this.
""".format(url_for('account.forgot', ref=ref, _external=True))
mail.send(msg)
</code></pre>