node发送qq邮箱

技术 · 2023-08-11 · 访问: 714 次

通过 nodemailer 模块来实现发送邮箱

安装:

npm install nodemailer

创建SMTP客户端配置

const nodemailer = require("nodemailer")

const config = {
  host: "smtp.qq.com", // QQ邮箱
  // smtp.163.com // 163邮箱
  port: 465, // 端口
  auth: {
    // 发件人邮箱账号
    user: "xxxxx@qq.com",
    // 发件人邮箱授权码,需要去QQ邮箱中申请
    pass: "xxxxx"
  }
}

const transporter = nodemailer.createTransport(config)

发送邮箱

const mail = {
  // 发件人邮箱,格式:"昵称<发件人邮箱>"
  from: "mmm<xxxxx@qq.com>",
  // 主题
  subject: "node发送邮箱测试",
  // 收件人邮箱,可以发送到其他邮箱
  to: "xxxxx@qq.com",
  // 内容
  text: "测试内容",
  // 可以添加html标签
  html: "<a href='https://www.ganjueblog.top'>博客</a>"
}

// 发送邮箱
transporter.sendMail(mail, function(error, info) {
  if(error) {
    return console.log(error)
  }
  transporter.close()
  console.log(info.response)
})

获取QQ邮箱授权码

Snipaste_2023-08-11_17-32-46.png

nodejs nodemailer
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
Theme Jasmine by Kent Liao