Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
105
第 11章
发送邮件
电子邮件是应用跟外界通信的主要途径之一。从用户注册到密码重置指引再到促销邮件,
发送邮件是网站的一个重要功能。本章将学习如何在
Node
和
Express
中格式化和发送邮
件,从而帮助你更好地跟用户沟通。
不管是
Node
还是
Express
,都没有内建邮件
发送功能,所以需要使用第三方模块。我要推
荐的是
Andris Reinman
的杰作
Nodemailer
。在开始配置
Nodemailer
之前,先来了解一下电
子邮件的一些基础知识,以扫清障碍。
11.1
 
SMTP
、
MSA
和
MTA
发送邮件的通用语言是简单邮件传输协议(
SMTP
)。尽管使用
SMTP
直接发送邮件到接
收者的邮件服务器是可行的,但除非是像谷歌或雅虎这样的受信任发送者,否则这么做
通常并不明智,因为你的邮件很可能会被直接扔进垃圾箱。最好是使用一个邮件发送代理
(
MSA
)
,它会通过受信任的通道投递邮件,从而减小邮件被标记为垃圾邮件的可能性。除
了保证邮件送达,
MSA
也可以处理诸如临时故障和邮件退回这些麻烦事。最后一个是邮件
投递代理(
M
TA
),它提供将邮件投递到最终目的地的服务。但对本书而言,
MSA
、
MTA
和
SMTP
服务器本质上是等效的。
接下来,你需要访问一个
MSA
。尽管也可以直接使用
Gmail
、
Outlook
或雅虎这样的免费
邮件服务,但是这些服务对自动化邮件已经没有过去那么友好了(为了尽量减少滥用)。
幸运的是,有两个非常出色的邮件服务(
SendGrid
和
Mailgun
)可供选择
,它们对低使用
量提供免费服务。这两个服务我都使用过,并且很喜欢。本书的示例将使用 ...
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

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099