
114
|
第
11
章
user: credentials.sendgrid.user,
pass: credentials.sendgrid.password,
},
})
const from = '"Meadowlark Travel <info@meadowlarktravel.com>'
const errorRecipient = 'youremail@gmail.com'
return {
send: (to, subject, html) =>
mailTransport.sendMail({
from,
to,
subject,
html,
text: htmlToFormattedText(html),
}),
}
}
如果现在要发送一封邮件,那么只需要这么做(版本库的
ch11/05-email-library.js
):
const emailService = require('./lib/email')(credentials)
emailService.send(email, "Hood River tours on sale today!",
"Get 'em while they're hot!")
11.9
小结
本章学习了如何在互联网上发送电子邮件。如果你跟着操作了,那么应该已经建立起了免
费邮件服务(很可能是
SendGrid
或
Mailgun
)
,并使用这个服务发送了文本和
HTML
邮件。
你也学习了如何使用模板来渲染邮件的 ...