我正在尝试使用Flask设置heroku应用程序,但在使用Flask-Mail时遇到了问题。
我可以从bash运行我的脚本,它每次都能工作,但当我把它推到Heroku时,它会工作一小段时间,然后就会停止。以下是脚本的相关部分:
from flask.ext.mail import Mail
from flask.ext.mail import Message
app.config.update(dict(
DEBUG = True,
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_TLS = False,
MAIL_USE_SSL = True,
MAIL_USERNAME = 'xxx@xxx.com',
MAIL_PASSWORD = 'xxx',
))
mail = Mail(app)
msg = Message(
'Hello',
sender = 'xxx@xxx.com',
recipients = ['xxx@xxx.com'])
msg.body = "This is the email body"
msg.html = '<b>HTML</b> body 1234'
with app.open_resource("image.jpg") as fp:
msg.attach("image.jpg", "image/jpg", fp.read())
@app.route('/test1')
def test1():
with app.app_context():
mail.send(msg)
return "Sent"我可以转到该路由并将其发送,但如果我在几分钟后再次尝试,页面将正常加载,但不会发送任何电子邮件。日志中未显示错误。
有没有人有办法解决这个问题?
发布于 2015-02-15 00:36:00
下面的配置是我在heroku中使用的配置。
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 587,
MAIL_USE_TLS = True,
MAIL_USE_SSL = False,
MAIL_USERNAME = 'my_username@gmail.com',
MAIL_PASSWORD = 'my_password',发布于 2015-01-19 11:27:05
我认为你需要使用Heroku插件(顺便说一句,它可以是免费的,但需要信用卡)。
https://stackoverflow.com/questions/27972621
复制相似问题