首页 > 编程语言 >node使用nodemailer发送邮件

node使用nodemailer发送邮件

时间:2023-02-18 10:44:06浏览次数:34  
标签:node qq 账号 nodemailer 发送 邮箱 com 邮件

安装模块

npm install nodemailer  

代码

const nodemailer = require('nodemailer');
// 查找到有关QQ邮箱的相关信息在 /node_modules/nodemailer/lib/well-known/services.json
//  "QQ": {
//         "domains": ["qq.com"],
//         "host": "smtp.qq.com",
//         "port": 465,
//         "secure": true
//     },
let transporter = nodemailer.createTransport({
  host: "smtp.qq.com", // 你可以通过services.json 文件中来获取
  port: 465, // 发邮箱的端口号
  secure:true, //自否自定义端口
  auth: { // 权限认证
    user: '[email protected]',
    pass: 'ckiibimilpipoh', //这是邮箱的授权码在邮箱后台生成的 
  }
})
 
let mailOptions = {
  from: '[email protected]', // 发邮件的账号
  to: '[email protected]', // 收邮件的账号
  subject: 'NODEMAILER', // 标题
  text:'你发送的内容',
}
 
transporter.sendMail(mailOptions, (err, info) => {
  if (!err) {
    console.log('邮件已经发生完成')
  } else {
    console.log('发送失败',err)
  }
})

如何配置QQ邮箱后台

1.进入QQ邮箱后台,点击左上角的设置

2.点击账号,找到 IMAP/SMTP服务(什么是IMAP,它又是如何设置?) 点击开启

3.用手机发送短信,确认开启

4.获取授权信息

关于出现错误

发送失败 Error: Message failed: 550 Mail content denied. 
1.检查接收账号/发送账号是否正确,我第一次就写错账号了。

nodemailer 官网地址

https://nodemailer.com/about/

标签:node,qq,账号,nodemailer,发送,邮箱,com,邮件
From: https://www.cnblogs.com/IwishIcould/p/17132108.html

相关文章