flask框架下发送邮件

各种邮箱的配置参考

百度经验-如何查看各种邮箱的服务SMTP/POP3地址及端口号
各种邮箱端口

163邮箱

1

QQ邮箱

2

代码

# -*- coding:utf-8 -*-


from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
# 配置邮箱
app.config.update(
	DEGUB=True,
	MAIL_SERVER="smtp.163.com",
	MAIL_PORT=465,
	MAIL_USE_SSL=True,
	MAIL_USERNAME="[email protected]",
	MAIL_PASSWORD="xxxxxxxxxx"
)
mail = Mail(app)


@app.route("/")
def index():
	msg = Message("This is a test", sender="[email protected]", recipients=["[email protected]"])
	msg.body = "Hello, KerrYoung"
	mail.send(msg)
	return "Send success!"


if __name__ == "__main__":
	app.run(debug=True)

测试

3

猜你喜欢

转载自blog.csdn.net/weixin_40775077/article/details/84931106
今日推荐