美文网首页
nodejs 实现发送邮件功能

nodejs 实现发送邮件功能

作者: 飞鱼_JS | 来源:发表于2017-08-26 23:14 被阅读0次
    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);
        });
    }

    相关文章

      网友评论

          本文标题:nodejs 实现发送邮件功能

          本文链接:https://www.haomeiwen.com/subject/ypnvdxtx.html