nodejs发送邮件

这里我主要使用的是 nodemailer 这个插件

第一步 下载依赖

cnpm install nodemailer --save

第二步 建立email.js

'use strict';

const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
  // host: 'smtp.ethereal.email',
  service: 'qq', // 使用了内置传输发送邮件 查看支持列表:https://nodemailer.com/smtp/well-known/
  port: 465, // SMTP 端口
  secureConnection: true, // 使用了 SSL
  auth: {
    user: 'xxxxxx@qq.com',//你的邮箱
    // 这里密码不是qq密码,是你设置的smtp授权码
    pass: 'qq的授权码',
  }
});

let mailOptions = {
  from: '"火星黑洞" <1418275530@qq.com>', // sender address
  to: '156093340@qq.com', // list of receivers
  subject: 'Hello', // Subject line
  // 发送text或者html格式
  // text: 'Hello 我是火星黑洞', // plain text body
  html: '<b>Hello 我是火星黑洞</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
  if (error) {
    return console.log(error);
  }
  console.log('Message sent: %s', info.messageId);
  // Message sent: <04ec7731-cc68-1ef6-303c-61b0f796b78f@qq.com>
});

第三步,执行 node email.js,即可发送成功~

 

注:可以前往 https://jingyan.baidu.com/article/fedf0737af2b4035ac8977ea.html 去查看如何设置授权码

 

 

转载于:https://www.cnblogs.com/ldlx-mars/p/9757827.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值