OSError:[错误2]当我尝试使用flask_mail发送邮件时,没有这样的文件或目录。 下面是我的代码:
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = parametter.email_sender
app.config['MAIL_PASSWORD'] = parametter.email_sender_password
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = False
mail = Mail(app)
@app.route('/')
def main():
msg = Message('Hello', sender = parametter.email_sender,recipients = [parametter.email_recipients])
msg.body = "Hello Flask message sent from Flask-Mail"
mail.send(msg)
return "Sent"
当我评论(#mail.send(msg))时,程序正常运行。但是我无法发送消息。有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
导入库时错了:
from flask.ext.mail import Mail, Message
应该是:
from flask_mail import Mail, Message