如何使用 Python 和 Flask 发送电子邮件 [英] How to send emails with Python and Flask

查看:44
本文介绍了如何使用 Python 和 Flask 发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在我的网站上工作,并尝试在用户创建帐户时发送确认电子邮件.我怎样才能在 Python 中做到这一点?我什至可以在我的 Flask 应用程序上用 Python 来做吗?我现在真的很困惑,可以使用一些帮助.非常感谢大家:)

I am working on my website right now and am trying to send a confirmation email when a user creates an account. How can I do this in Python? Can I even do it in Python on my Flask app? I'm really confused right now and could just use some help. Thank you all so much :)

推荐答案

您可以使用 flask_mail为此目的

要使其工作,请以这种方式设置参数:

To make it work set parameters this way:

app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = 'youremail@gmail.com' # your email
app.config['MAIL_PASSWORD'] = 'your-password' # your password

同时转到您的谷歌帐户安全设置并启用不太安全的应用访问",但谷歌并不真正喜欢它,有时你仍然会出错.在这种情况下,只需尝试使用解冻设置,关闭并再次打开,在某些时候它肯定会起作用(我非常确信,因为这对我完全有用)

Also go to your google account security settings and enable 'Less secure app access’, but google doesn’t really like it and still sometimes you can get errors. In this case just try to play with thaws settings, turn things off and on again, at some point it should definitely work (I’m so convinced, cause this totally works for me)

您也可以在谷歌设置中使用应用专用密码.

You also can use the app-specific password in google settings.

这篇关于如何使用 Python 和 Flask 发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆