nodejs 实现发送邮件功能

const nodemailer = require('nodemailer');

```function senEmail(message) {
    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
        host: 'smtp.163.com',
        port: 465,
        secure: true, // secure:true for port 465, secure:false for port 587
        auth: {
            user: 'hello_jinyu@163.com',
            pass: 'ljy6585529'
        }
    });
    // setup email data with unicode symbols
    let mailOptions = {
        from: '"iPalmap" <hello_jinyu@163.com>', // sender address
        to: `597396238@qq.com`, // list of receivers
        subject: '定位发生异常', // Subject line
        text: message // plain text body
            // html: '<h1>定位发生异常</h1>' // html body
    };
    // send mail with defined transport object
    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log("---------", error);
        }
        // console.log(info)
        console.log('Message %s sent: %s', info.messageId, info.response);
    });
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容