使用Node发送邮件验证码

163邮箱

开启POP3/SMTP服务

开启pop3/smtp服务
确认开启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'
		}
	]
})

注意事项

注意:

  1. 注意端口号配置是否正确
  2. pass 参数是授权密码,不是登录密码
  3. 授权密码 有效期 180天

阿里云企业邮箱

开启POP3/SMTP服务

登录邮箱
打开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'
		}
	]
})

注意事项

注意:

  1. 注意端口号配置是否正确
  2. pass 参数是 登录密码 注意与163邮箱的授权密码进行区分
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值