前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Node.js还可以发邮件

使用Node.js还可以发邮件

作者头像
马克社区
发布2022-06-13 12:04:08
5550
发布2022-06-13 12:04:08
举报
文章被收录于专栏:高端IT高端IT

前言

今天,我们给大家开发一个小效果。篇幅比较短,主要给大家展示效果。 实战

代码语言:text
复制
首先我们初始化一个Node项目

npm init -y


创建一个app.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: 'xxx@qq.com', // 这里以QQ邮箱为例
    pass: 'kzudmlwerknibejc', // 设置的smtp授权码
  }
});

let mailOptions = {
  from: '"xxx" <xxx@qq.com>', // sender
  to: 'xxx@163.com', // receivers
  subject: 'Hello', // Subject line
  // 发送text或者html格式
  // text: 'Hello world?', // plain text body
  html: '<b>Hello world?</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>
});


Nodemailer是一个简单易用的Node.js邮件发送组件。

官网地址:https://nodemailer.com

GitHub地址:https://github.com/nodemailer/nodemailer

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119809451

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档