Node.js | 更tech地解决Excel表的邮件地址

《Node.js | 更tech地解决Excel表的邮件地址》 Node-xlxs-mail

Dependencies

  • <a href=”https://nodejs.org/en/”>Node.js </a>
  • <a href=”https://nodemailer.com/about/”>Nodemailer </a>基于Node的邮件代理库,要求Node.js v6+
  • <a href=”https://github.com/SheetJS/js-xlsx”>js-xlxs</a>目前 Github 上 star 数量最多的处理 Excel 的库

Story

因为组织<a href=”http://mp.weixin.qq.com/s?biz=MzAxMjkxNTY2OQ==&mid=2247484454&idx=2&sn=b7ede3f8d08b4cc3995965e0b103868e&chksm=9babc29cacdc4b8a0b8e86e6a13cd93ef02e3cf343d911035e4abc0fdfa8a99bd5ccc78cd563&mpshare=1&scene=1&srcid=02281tg2ge28hsVEJOx9GKSl#rd” >02-25的FreeCodeCamp-GZ的线下交流活动</a>,需要通知已经报名的小伙伴,看着excel表的邮箱地址s(这里要用复数形式o( ̄︶ ̄)o),脸上的表情是这样的=>(o)/YES!,内心要发提醒邮件的小人的表情是这样的=>(o´・ェ・`o)ค(TㅅT)。
作为一个沉迷学习和电视剧的我,于是写个<a href=”https://github.com/CaiYiLiang/Node-xlxs-mail”>脚本:Node-xlxs-mail</a>实现自动抓取Excel里的邮箱地址并自动发送邮件,省下来的时间可以看一集Modern Familyค(*^
^*)ค

How to use

假定你已经安装Node.js v6+
虽然好像很多文字的样子!!但只需要简单4步!!!o( ̄︶ ̄)o
虽然好像很多文字的样子!!但只需要简单4步!!!(๑•̀ㅂ•́)و✧
虽然好像很多文字的样子!!但只需要简单4步!!!ヽ(✿゚゚)ノ

Step 0 : 获取项目源码:Node-xlxs-mail
  • 直接下载
    <a href=”https://github.com/CaiYiLiang/Node-xlxs-mail”>SourceCode – 欢迎随手(≧≦)/</a>
  • git command 下载
    git clone git@github.com:CaiYiLiang/Node-xlxs-mail.git
Step 1 :开启你的smtp mail 服务

在开始写代码前,先确认你用什么邮箱来发邮件,然后简单设置一下你的smtp mail设置。

《Node.js | 更tech地解决Excel表的邮件地址》 smtp-gmail-setting

题外话:

  • 作者使用的smtp是gmail, 除了连接有时会 ETIMEOUT 理解一下,毕竟google在某些地方不稳定<( ̄ˇ ̄)/其余的都没什么问题。
    <a href=”https://support.google.com/mail/answer/7104828?hl=zh-Hant”>传送门:smtp gmail 设置</a>
    <a href=”https://www.google.com/settings/security/lesssecureapps”>传送门:turn on access Less secure apps</a>
  • 使用网易163,但是经常被163禁止发送,返回error code 554 DT:SPM 网易系统识别为垃圾邮件 ,测试了下只有happy birthday的字眼才能顺利发送出去,我真的无能为力Ψ( ̄∀ ̄)Ψ.
  • 使用QQ smtp服务,需要在邮箱开启smtp的选项,然后需要绑定手机,那就绑呗(我有手机我自豪︿( ̄︶ ̄)︿),然后手机绑定要先输入密保三个问题的密保!!我真的无能为力Ψ( ̄∀ ̄)Ψ.
    <a href=”http://www.jianshu.com/p/ee200a67853c”>Node.js使用NodeMailer发送邮件 – 网易邮箱/QQ的smtp mail设置</a>
Step 2 :更新你的excel表和邮箱信息

cd Node-xlxs-mail

需要<b>改动</b>的只有三个地方

  • test.xlsx 替换成你的excel文件(或者直接在excel添加你的测试邮箱)
  • mailContext.js 更新你邮箱的smtp信息(其它的可以先不改)
    <a href=”https://www.freehao123.com/mail-smtp/”>传送门:各大免费邮箱邮件群发账户SMTP服务器配置</a>
  • 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```


![Success Send](http://upload-images.jianshu.io/upload_images/2628066-02a1866aad198058.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![ETIMEOUT-请求超时,或者可以像gamil建议改为5分钟](http://upload-images.jianshu.io/upload_images/2628066-11a323e8d816bcda.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##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:
<a href="http://www.jianshu.com/p/ee200a67853c">Node.js使用NodeMailer发送邮件</a>
<a href="https://aotu.io/notes/2016/04/07/node-excel/">Node读写Excel文件探究实践</a>

---
> ####原创文章
   简书:<a href="http://www.jianshu.com/u/c0600377679d">HelloCherry</a>
   Github: <a href="https://github.com/CaiYiLiang">CaiYiLiang</a>
  其它推荐:<a href="http://www.jianshu.com/p/d7e48ef76eae">【Git】PR:让开源项目merge你的代码</a>
本文源码:<a href="https://github.com/CaiYiLiang/Node-xlxs-mail">SourceCode - 欢迎随手~(≧≦)/~</a>

如果觉得有一点点帮助,一个❤❤就是鼓励(。⌒∇⌒)


















·
    原文作者:HelloCherry
    原文地址: https://www.jianshu.com/p/7a35fa90810f
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞