uni-app学习笔记之163邮箱自动发邮件

前期准备

  1. 注册163邮箱
  2. 在邮箱设置中开启POP3/SMTP服务
  3. 新增授权密码(记得保存)
  4. 新建云函数目录mail163
  5. 安装 nodemailer 模块
    在mail163目录右键—>“使用命令行窗口打开所在的目录”—>npm install nodemailer -s
//index.js
'use strict';
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
	host: "smtp.163.com", //邮箱服务器  这里我用的163邮箱
	port: 465, //邮箱使用端口
	secure: true, //是否使用默认的465端口
	auth: {
		user: "16620122910@163.com",
		pass: "XXXXXXXXXXXXXXX"
	}
});
/*
 * option{
 *	from 从何处发送 默认主人邮箱
 *	to 发往何处 必填
 *	subjec 标题 必填
 * 	text 文本消息 与html必填其一
 *	html html消息 与text必填其一
 * }
 */
function sendMail(option) {
	return new Promise((resolve, reject) => {
		nodemailer.createTestAccount((err) => {
			if (err) return reject("创建失败");
			transporter.sendMail(option, (error) => {
				if (error) return reject("发送失败");
				resolve("发送成功");
			});
		})
	})
}
exports.main = async (event, context) => {
	return await sendMail(event.option);
};

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光明有我16620122910

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值