基于node的邮件服务
定时每日给女友们发送情话嘿嘿嘿
就是照着大佬学习的
Github项目地址html
yarn init
建立一个package.json以163邮箱为例node
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邮箱只显示一次,注意保存。
其余邮箱步骤大体相同。ios
② 经常使用邮箱服务器地址及端口git
transporter.sendMail({ from: user, // 163若是from和auth中的user不一致会发送失败,而qq邮箱能够加定制话语`你的爱人${user}` to: to, subject: title, text: text, })
Github项目地址github