发送 QQ 邮件 - nodemailer
什么是 POP3/IMAP/SMTP 服务
如何打开 POP3/SMTP/IMAP 功能?
示例
ts
import nodemailer from 'nodemailer'
const transporter = nodemailer.createTransport({
host: 'smtp.qq.com',
port: 465,
secure: true, // true for port 465, false for other ports
auth: {
user: 'xxx@qq.com',
pass: '授权码',
},
})
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// send mail with defined transport object
const info = await transporter.sendMail({
from: '"QQ邮箱 👻" <xxx@qq.com>', // sender address
to: 'xxx@qq.com, xxx@gmail.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<h1>Hello world?</h1>', // html body
})
console.log('Message sent: %s', info.messageId)
}
main().catch(console.error)