node-send-email
v2.0.4
Published
This is a dependency package based on nodemailer for nodejs to send mail, which combines the required parameters and is more convenient to use.
Downloads
54
Readme
node-send-email.js
English
Introduce
This is a dependency package based on nodemailer for nodejs to send mail, which combines the required parameters and is more convenient to use.
Use
Two parameters:
- parameter object, params, which defines some sending configurations.
- callback function, with the result value of Boolean type, to determine whether the transmission is successful.
//...
const {sendMail} = require('node-send-email')
//...
app.post('/api/email', async (req, res) => {
//...
const code = String(Math.floor(Math.random() * 1000000)).padEnd(6, '0') //Generate random verification code
// Parameters required for sending mail
const params = {
// Email type, @qq.com will send qq, @163.com will send 163, otherwise, it will be qq by default.
// Other types can be found in node_nodules/node-send-email/lib/service.js.
type:'qq',
// addresser
name: 'moon',
// outbox
from: '[email protected]',
// Outbox smtp, mailbox-Settings-Account -POP3/SMTP service-Open-Get stmp authorization code
smtp: 'xxxxxxxxx',
// Send the subject of the message
subject: 'verification code',
// Inbox
to: '[email protected]',
// Mail content, HTML format
html: `
<p>howdy!</p>
<p>Your verification code is:<strong style="color:orangered;">${code}</strong></p>
<p>If you didn't do it yourself, please ignore this email.</p>
`
};
await sendMail(params, (result,info) => {
if (result) {
res.send({code: 1, msg: 'Sending verification code succeeded'})
} else {
res.send({code: 0, msg: 'Failed to send verification code, please try again later.'})
console.log(info)
}
})
});
中文
介绍
这是一个基于nodemailer用于nodejs发送邮件的依赖包,将需要参数合并到了一起,使用更便捷。
使用
两个入参:
- 一个参数对象,params,定义一些发送配置。
- 一个回调函数,result值为Boolean类型,判断是否发送成功。
//...
const {sendMail} = require('node-send-email')
//...
app.post('/api/email', async (req, res) => {
//...
const code = String(Math.floor(Math.random() * 1000000)).padEnd(6, '0') //生成随机验证码
//发送邮件需要的入参
const params = {
// 邮箱类型,@qq.com就传qq,@163.com就是传163,不传的话默认为qq
// 其余类型可以在node_modules/node-send-email/lib/service.js中找到
type:'qq',
// 发件人
name: '月亮',
// 发件箱
from: '[email protected]',
// 发件箱smtp,邮箱—设置–账户–POP3/SMTP服务—开启—获取stmp授权码
smtp: 'xxxxxxxxx',
// 发送的邮件主题
subject: '验证码',
// 收件箱
to: '[email protected]',
// 邮件内容,HTML格式
html: `
<p>您好!</p>
<p>您的验证码是:<strong style="color:orangered;">${code}</strong></p>
<p>如果不是您本人操作,请无视此邮件</p>
`
};
await sendMail(params, (result,info) => {
if (result) {
res.send({code: 1, msg: '发送验证码成功'})
} else {
res.send({code: 0, msg: '发送验证码失败,请稍后重试'})
console.log(info)
}
})
});