Dependencies
- Node.js
- Nodemailer
基于Node的邮件代理库,要求Node.js v6+
- js-xlxs
目前 Github 上 star 数量最多的处理 Excel 的库
Story
因为组织02-25的FreeCodeCamp-GZ的线下交流活动,需要通知已经报名的小伙伴,看着excel表的邮箱地址s(这里要用复数形式o( ̄︶ ̄)o),脸上的表情是这样的=>(^o^)/YES!,内心要发提醒邮件的小人的表情是这样的=>(o´・ェ・`o)ค(TㅅT)。
作为一个沉迷学习和电视剧的我,于是写个脚本:Node-xlxs-mail实现自动抓取Excel里的邮箱地址并自动发送邮件,省下来的时间可以看一集Modern Familyค(^__^)ค
How to use
假定你已经安装Node.js v6+
虽然好像很多文字的样子!!但只需要简单4步!!!o( ̄︶ ̄)o
虽然好像很多文字的样子!!但只需要简单4步!!!(๑•̀ㅂ•́)و✧
虽然好像很多文字的样子!!但只需要简单4步!!!ヽ(✿゚゚)ノ
Step 0 : 获取项目源码:Node-xlxs-mail
- 直接下载
SourceCode - 欢迎随手~(≧≦)/~ - git command 下载
git clone git@github.com:CaiYiLiang/Node-xlxs-mail.git
Step 1 :开启你的smtp mail 服务
在开始写代码前,先确认你用什么邮箱来发邮件,然后简单设置一下你的smtp mail设置。
题外话:
- 作者使用的smtp是gmail, 除了连接有时会
ETIMEOUT 理解一下,毕竟google在某些地方不稳定
<( ̄ˇ ̄)/其余的都没什么问题。
传送门:smtp gmail 设置
传送门:turn on access Less secure apps- 使用网易163,但是经常被163禁止发送,返回error code
554 DT:SPM 网易系统识别为垃圾邮件
,测试了下只有happy birthday
的字眼才能顺利发送出去,我真的无能为力Ψ( ̄∀ ̄)Ψ.- 使用QQ smtp服务,需要在邮箱开启smtp的选项,然后需要绑定手机,那就绑呗(我有手机我自豪︿( ̄︶ ̄)︿),然后手机绑定要先输入密保三个问题的密保!!我真的无能为力Ψ( ̄∀ ̄)Ψ.
Node.js使用NodeMailer发送邮件 - 网易邮箱/QQ的smtp mai…
Step 2 :更新你的excel表和邮箱信息
cd Node-xlxs-mail
需要改动的只有三个地方
-
test.xlsx
替换成你的excel文件(或者直接在excel添加你的测试邮箱) -
mailContext.js
更新你邮箱的smtp信息(其它的可以先不改)
传送门:各大免费邮箱邮件群发账户SMTP服务器配置 -
parseExcel.js
①如果你的excel文件不是命名为test.xlsx
,需要在这里改回相应的名字XLSX.readFile('yourexcel-name.xlsx')
;
②以及如果指定邮箱地址在第几列,本demo是在第三列el[index[2]]
。
以下是项目文件结构:
├── index.js
├── log4js_confg.json
├── test.xlsx replace your excel with email-address
├── package.json
├── .gitignore
├── README.md
├── src
│ ├── mailContext.js update your mail-info : your smtp mail service info
│
├── parseExcel.js update excel name if your excel is not named 'test.xlxs'
├── logs
│ ├── logs...
├── img
│ ├── imgs... `
Step 3 :抓取Excel表的邮件地址,并发送邮件
# install dependencies
npm install
# run the script
node index.js
Why
这里只是关于我思考的絮絮叨叨:
- 为什么不是把邮件一次性群发到所有的邮箱地址?
parseExcel.mailList.forEach(mailAddress => { setTimeout(sendMail, 5000 , mailAddress); });
1.If the message includes several recipients then the message is considered sent if at least one recipient is accepted
如果群发,只要有一封邮件发出去都会显示为发送成功。
---来自官网
2.To avoid mail service party block your mails when you sent to their port at a time 。
防止一次性发送过去属于同一个服务商的邮件被bloked。
---来自实践的思考
Reference:
Node.js使用NodeMailer发送邮件
Node读写Excel文件探究实践
原创文章
简书:HelloCherry
Github: CaiYiLiang
其它推荐:【Git】PR:让开源项目merge你的代码
本文源码: SourceCode - 欢迎随手~(≧≦)/~
如果觉得有一点点帮助,一个❤❤就是鼓励(。⌒∇⌒)
·