使用Node.js还可以发邮件
2024-09-08 02:48:34
前言
今天,我们给大家开发一个小效果。篇幅比较短,主要给大家展示效果。
实战
首先我们初始化一个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
最新文章
- ListBox实现拖拽排序功能
- CCSprite的使用方法大全
- HDU-4418 Time travel 概率DP,高斯消元
- MSSTDFMT.dll系统文件(附2种MSSTDFMT.dll 注册方法)-系统增强
- three.js 源代码凝视(十六)Math/Frustum.js
- PPT素才搜索简谈
- CentOS通过yum安装php7.0
- 4. svg学习笔记-文档结构元素和样式的使用
- 对如下字符串(234453)[234]{2324}分析它的括号使用是否正确,括号匹配(Java实现)
- oracle sql语句实现累加、累减、累乘、累除
- 整合mybaties 逆向生成 pojo mapper.xml
- fedora如何删除某个包且不删除依赖它的相关包
- Python Json模块中dumps、loads、dump、load函数介绍
- Javascript、Jquery获取浏览器和屏幕各种高度宽度(单位都为px)
- 一行一行读Java源码——LinkedBlockingQueue
- JVM调优总结(一):基本概念
- Going Home(最小费用最大流)
- IE8下window.open 二次无法加载页面
- linux 用户和组操作
- hibernate实现学生-课程-成绩
热门文章
- C++ functional库中的仿函数
- pycharm的安装指导教程以及破解
- Linux内核--链表结构(二)
- C++篇:第四章_函数_知识点大全
- 前端性能优化之js,css调用优化
- 论文解读(BGRL)《Bootstrapped Representation Learning on Graphs》
- React项目中使用wangeditor以及扩展上传附件菜单
- 21天学通Python PDF完整版
- 忘记VMware vcenter的Administrator@vsphere.local密码
- Oracle 数据库表删除重复数据