node nodemailer

参考 https://nodemailer.com/about/

安装 

npm install nodemailer --save

sendEmail.js

const nodemailer = require('nodemailer');
const config = {
    email:{
        host: 'smtp.exmail.qq.com',
        port: 465,
        secure: true,
        user: 'example@qq.com',
        pass: 'UZNmJxTgbekA949o',
        from: 'example@qq.com',
        subject: '您的密码重置完成',
    },
};

async function sendEmail(address,passwordInfo) {
    let account = await nodemailer.createTestAccount();
    console.log('Credentials obtained, sending message...');
    // Create a SMTP transporter object
    let transporter = nodemailer.createTransport(
        {
            host: config.email.host,
            port: config.email.port,
            secure: config.email.secure,
            auth: {
                user: config.email.user,
                pass: config.email.pass
            },
            logger: false,
            debug: false
        },
        {
            from: config.email.from,
        }
    );

    let info = await transporter.sendMail(
        {
            to: address,
            subject: config.email.subject,
            text: `新密码为:${passwordInfo}`,
            html: ''
        }
    );
    console.log('Message sent successfully!');
    console.log('Server responded with "%s"', info.response);
    transporter.close();
}

module.exports = sendEmail;

调用

const SendEmail= require("./SendEmail");
//
SendEmail("123456@qq.com", 123456);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值