使用Node发送邮件验证码
163邮箱
开启POP3/SMTP服务


记录授权密码

启用成功如下图

代码示例
import { createTransport } from 'nodemailer'
import type { Mailer } from 'nodemailer'
const transport = createTransport({
host: 'smtp.163.com',
port: 465,
secure: true,
auth: {
user: 'user@163.com',
psss: '授权密码'
}
})
transport.sendMail({
from: '发送者邮箱账号',
to: '接收者邮箱账号',
subject: '邮件标题',
text: '发送的邮件内容',
html: '<h1>html内容</h1>',
attachments: [
{
filename: '附件名称1',
path: '附件路径1'
},
{
filename: '附件名称2',
path: '附件路径2'
}
]
})
注意事项
注意:
- 注意端口号配置是否正确
pass参数是授权密码,不是登录密码- 授权密码
有效期 180天
阿里云企业邮箱
开启POP3/SMTP服务


代码示例
import { createTransport } from 'nodemailer'
import type { Mailer } from 'nodemailer'
const transport = createTransport({
host: 'smtp.qiye.aliyun.com',
port: 465,
secure: true,
auth: {
user: '阿里云企业邮箱账号',
psss: '阿里云企业邮箱密码'
}
})
transport.sendMail({
from: '已开通smtp服务的邮箱账号',
to: '接收者邮箱账号',
subject: '邮件标题',
text: '发送的邮件内容',
html: '<h1>html内容</h1>',
attachments: [
{
filename: '附件名称1',
path: '附件路径1'
},
{
filename: '附件名称2',
path: '附件路径2'
}
]
})
注意事项
注意:
- 注意端口号配置是否正确
pass参数是登录密码注意与163邮箱的授权密码进行区分

被折叠的 条评论
为什么被折叠?



