用Nodemailer发个邮件不算难?
公司一直用邮箱做一些部门间协调的沟通留存,于是乎想用点“编程思维”做些“工作流”来自动化处理;但是公司用的邮箱有点难登呐!
选用的Nodejs 作为实现语言,那就用Nodemailer来发吧
上Demo代码测试一下
const nodemailer = require("nodemailer");// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
// let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "mail.***.com.cn",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: 'username', // generated ethereal user
pass: '********', // generated ethereal password
},
ignoreTLS: true,
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Jimmy " <**@**.com.cn>', // sender address
to: "***@**.com.cn", // list of receivers
subject: "Hello ", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
date: new Date('2021-03-30 23:59:59'),
});
console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview only available when sending through an Ethereal account
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
但等都登不上去 哈哈哈哈果然是难得顺利
于是乎开始全网查资料.....
终于查到一些思绪
需要使用telnet登上服务器看看
telnet smtp.****.com.cn 587
Connected to mail.****.cn.
Escape character is '^]'.
220 ex01.***.cn Microsoft ESMTP MAIL Service ready at Fri, 23 Apr 2021 18:08:13 +0800
ehlo
250-ex01.****.cn Hello [123.233.***.***]
250-SIZE 1073741824
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH GSSAPI NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 XRDST

原来如此 和一般的是不太一样
继续面向搜索引擎编程~~
找来找去没有比较好的轮子,差点就像自己来造起了
在翻翻文档瞧瞧

发现了个实现过的轮子 wow~
最终经过一番调教终于收到自己给自己发送的邮件
const nodemailer = require("nodemailer");
const nodemailerNTLMAuth = require('nodemailer-ntlm-auth');
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
// let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.****.com.cn",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
type: 'custom',
method: 'NTLM',
user: 'username', // generated ethereal user
pass: '*******', // generated ethereal password
},
ignoreTLS: true,
customAuth: {
NTLM: nodemailerNTLMAuth,
}
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Jimmy " <*****@*****.com.cn>', // sender address
to: "***@***.com.cn", // list of receivers
subject: "Hello ", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>", // html body
date: new Date('2021-03-30 23:59:59'),
});
console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview only available when sending through an Ethereal account
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
打印邮件ID
Message sent: <466d4875-00e7-e9fa-11dd-e6b65d1b023f@***.com.cn>
OK!待续
EOF
用Nodemailer发个邮件不算难?的更多相关文章
- 【nodemailer】 之邮件附件
nodemailer 续 之前对nodemailer做了一个简单的了解,这篇文章主要研究一下如何添加附加文件 测试代码 //Created by yyrdl on 2015/10/2. var nod ...
- SQLSERVER监控复制并使用数据库邮件功能发告警邮件
SQLSERVER监控复制并使用数据库邮件功能发告警邮件 最近熬出病来了,都说IT行业伤不起,不说了,说回今天的正题 正题 上个月月底的时候因为要搬迁机房,需要将一个数据信息数据库先搬到我们的机房,然 ...
- PHPMailer发匿名邮件及Extension missing: openssl的解决
原文链接:http://www.tongfu.info/phpmailer%E5%8F%91%E5%8C%BF%E5%90%8D%E9%82 %AE%E4%BB%B6%E5%8F%8Aextensio ...
- python发QQ邮件
python发qq邮件相对比较简单,网上教程一大把:固定套路,后面封装看自己怎么方便可以怎样进行封装:原版代码如下: """ # -*- coding : utf-8 - ...
- nodemailer 发邮件
var transporter = nodemailer.createTransport({//v1.0 above do not use 'SMTP' as first param host: &q ...
- nodeJs的nodemailer发邮件报错hostname/IP doesn't match certificate's altnames怎么解决?
今天在开发过程中碰到一个问题,即使用node发送邮件时报错hostname/IP doesn't match certificate's altnames,在网上查了解决办法有两个, 加rejectU ...
- 使用Spring整合javaMail发用邮件
1.导入javamail.jar 自行百度下载 2.使用模板发送邮件架包 freemarker.jar 3.Spring配置文件 以及架包这里就不需要说了吧,如果不明白的发我Email ...
- mailx 乱码,sendmail发html邮件,脚本开机启动
echo "yes"|mailx -s "我" -S ttycharset=utf-8 -S sendcharsets=utf-8 -S encoding=ut ...
- 发测试邮件或垃圾邮件node脚本
npm install nodemailer 执行后,指定目录下会出现node_modules模块,再相同目录下,创建main.js,js代码如下: var nodemailer = require( ...
- postfix疯狂外发垃圾邮件
分析 一.查找main.cf配置文件 localhost# find / -name main.cf /etc/postfix/main.cf 二.打开/etc/postfix/main.cf来看看. ...
随机推荐
- BST 插入节点传新版本(原痛恨JavaScript每一天 __ 没有指针)
2023年2月2日更新 perform代码上传到GitHub了,新方法比老方法慢,不建议在生产环境使用 GitHub地址:https://github.com/Dou-fugan/webDemo/tr ...
- Python 发展趋势:与 Rust 深度融合、更易于编写 Web 应用
大家好,我是猫哥,好久不见!2022 年末的时候,我不可避免地阳了,借着身体不舒服就停更了,接踵而至的是元旦和春节假期,又给自己放了假,连年终总结也鸽了,一懈怠就到了 2 月中旬-- 现在是我家娃出生 ...
- 【译】使用 ML.NET 进行机器学习 - 集群完整指南
原文 | Nikola M. Zivkovic 翻译 | 郑子铭 在之前的几篇文章中,我们探索了一些基本的机器学习算法.到目前为止,我们介绍了一些简单的回归算法,分类 算法.我们使用 ML.NET 实 ...
- 无法加载 DLL“*******.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
无法加载 DLL"Lib\WeWorkFinanceSdk.dll": 找不到指定的模块. (异常来自 HRESULT:0x8007007E). 网上查找了一大堆,没找到是什么问题 ...
- C# winform 一个窗体需要调用自定义用户控件的控件名称
给用户控件ucQRCode增加属性: //二维码图片 private PictureBox _pictureBoxFSHLQrCode; public PictureBox PictureBoxFSH ...
- 微信小程序-【转发好友】以及中文标题乱码问题解决
微信小程序的转发功能,参考官方文档,使用的buttom的open-type功能,下面是转发功能的具体实现. // 通过按钮的 open-type="share"实现转发,触发onS ...
- LeetCode-537 复数乘法
来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/complex-number-multiplication 题目描述 复数 可以用字符串表示,遵循 ...
- 运维排查篇 | Linux 连接跟踪表满了怎么处理
nf_conntrack (在老版本的 Linux 内核中叫 ip_conntrack )是一个内核模块,用于跟踪一个网络连接的状态 一旦内核 netfilter 模块 conntrack 相关参数配 ...
- pdf.js打开后的pdf文件
可用pdf.js在h5打开pdf文件.注意,在本地打不开,一定要在部署环境. 方法:<a href="../../pdf/web/viewer.html?file=../../pdf/ ...
- RISC-V核及工具链整理
RISC-V开源核分为开源核(无外设).SOC.FPGA.多核等多种框架. 开源核 SOC框架 平头哥无剑100 包括EDA仿真框架及FPGA框架 https://github.com/T-head- ...