node-mail-service
基于node的邮件服务
定时每日给女朋友们发送情话嘿嘿嘿
就是照着大佬学习的
Github我的项目地址
启动服务
- git clone 本我的项目
- yarn install 或 npm install
- yarn serve 或 npm run serve
创立你的邮件服务
- 找一个你喜爱的文件夹执行
yarn init
创立一个package.json - yarn add nodemailer axios node-schedule 下载要用到的三个依赖:获取情话、邮件服务、定时工作
- 去你的邮箱开启邮件服务并获取受权码
- 创立index并根据本我的项目实现邮件服务
- node index 或 yarn serve 启动服务;终端顺次显示爱心启动、你的情话、行将收回、发送胜利|发送失败
配置邮箱服务
以163邮箱为例
function sendMail(text, title = "敬爱的小宝贝") { const user = "你的163邮箱@163.com"; // 用163邮件服务就应用你的163邮箱,用qq邮件服务就用qq邮箱 const pass = "你的受权码"; // 邮箱受权码,见下① const to = "对方的邮箱@qq.com"; // 对方的邮箱,任意邮箱 const transporter = nodemailer.createTransport({ service: '163', host: "smtp.163.com", port: 994, // 不同的邮箱端口号不同,见下罕用邮箱服务器地址及端口② secure: true, auth: { user: user, // 用户账号 pass: pass, //受权码 }, }); console.log('行将收回'); transporter.sendMail({ from: user, to: to, subject: title, text: text, }).then(res => { console.log('发送胜利:', res); }).catch(err => { console.log('发送失败:', err); });}
注:
① 进入你的邮箱,找到左上角账号前面的设置,抉择POP3/SMTP/IMAP设置,开启IMAP/SMTP服务、POP3/SMTP服务发个短信即可,
短信发完下面会显示你的受权码
,163邮箱只显示一次,留神保留。
其余邮箱步骤大致相同。
② 罕用邮箱服务器地址及端口
常见问题
- 163无限不能定制邮件的from和to
transporter.sendMail({ from: user, // 163如果from和auth中的user不统一会发送失败,而qq邮箱能够加定制话语`你的爱人${user}` to: to, subject: title, text: text, })
上传到服务器
- 选一个你喜爱的服务器
- 选一个你喜爱的xshell或其余什么玩意
- 选一个你喜爱的pm2下载姿态
- 选一个你喜爱的pm2运行node index
Github我的项目地址