Skip to Content
Flask Web开发:基于Python的Web应用开发实战(第2版)
book

Flask Web开发:基于Python的Web应用开发实战(第2版)

by Miguel Grinberg
August 2018
Intermediate to advanced
230 pages
6h 42m
Chinese
O'Reilly Media, Inc. Beijing
Content preview from Flask Web开发:基于Python的Web应用开发实战(第2版)
6
电子邮件
很多类型的应用都需要在特定事件发生时通知用户,而常用的通信方法是电子邮件。本章
介绍如何在
Flask
应用中发送电子邮件。
使用
Flask-Mail
提供电子邮件支持
虽然
Python
标准库中的 smtplib 包可用于在
Flask
应用中发送电子邮件,但包装了 smtplib
Flask-Mail
扩展能更好地与
Flask
集成。
Flask-Mail
使用
pip
安装:
(venv) $
pip install flask-mail
Flask-Mail
连接到简单邮件传输协议(
SMTP
simple mail transfer protocol
)服务器,把邮
件交给这个服务器发送。如果不进行配置,则
Flask-Mail
连接
localhost
上的
25
端口,无
须验证身份即可发送电子邮件。表
6-1
列出了可用来设置
SMTP
服务器的配置。
6-1Flask-Mail SMTP服务器的配置
配置 默认值 说 明
MAIL_SERVER
localhost
电子邮件服务器的主机名或
IP
地址
MAIL_PORT
25
电子邮件服务器的端口
MAIL_USE_TLS False
启用传输层安全(
TLS
transport layer security
)协议
MAIL_USE_SSL False
启用安全套接层(
SSL
secure sockets layer
)协议
MAIL_USERNAME None
邮件账户的用户名
MAIL_PASSWORD None
邮件账户的密码
在开发过程中,连接到外部
SMTP
服务器可能更方便。举个例子 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python机器学习基础教程

Python机器学习基础教程

Andreas C. Müller, Sarah Guido
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
程序设计导论:Python语言实践

程序设计导论:Python语言实践

罗伯特 塞奇威克, 凯文 韦恩, 罗伯特 唐德罗

Publisher Resources

ISBN: 9787115489456