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

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容