美文网首页
使用node.js发送邮件 ---- nodemailer

使用node.js发送邮件 ---- nodemailer

作者: 彬彬彬boboc | 来源:发表于2019-04-20 15:17 被阅读0次

    1、安装nodemailer模块

    npm install --save nodemailer

    2、引入nodemailer模块

    const nodemailer = require("nodemailer");

    3、复制粘贴

    const nodemailer = require("nodemailer");

    async function main(){

      let testAccount = await nodemailer.createTestAccount();

      let transporter = nodemailer.createTransport({

        host: "smtp.qq.com",  //邮件服务器 这里使用qq的

        port: 465,

        secure: true, // true for 465, false for other ports

        auth: {

          user: "000000000@qq.com", // 发送者的邮箱地址

          pass: "oooooooooo" // 发送者的邮箱授权码

        }

      });

      let info = await transporter.sendMail({

        from: 'xxxxxx@qq.com', // 发送者

        to: "xxxxxxxx@163.com", // 接收者  多个使用逗号隔开

        subject: "Hello ✔", // 邮件主题

        text: "Hello world?", // 文件内容

        html: "<b>Hello world?</b>" // html内容

      });

      console.log(info)   //打印发送后返回的东西

    }

    main().catch(console.error);

    说明:如何获得邮箱的授权码

    https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256%27

    好了,这一波妥妥的,绝逼能用

    相关文章

      网友评论

          本文标题:使用node.js发送邮件 ---- nodemailer

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