前端开发Web前端之路技术干货

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

2017-03-01  本文已影响410人  HelloCherry
Node-xlxs-mail

Dependencies

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
Step 1 :开启你的smtp mail 服务

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

smtp-gmail-setting

题外话:

Step 2 :更新你的excel表和邮箱信息

cd Node-xlxs-mail

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

以下是项目文件结构:
├── 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:https://img.haomeiwen.com/i2628066/02a1866aad198058.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![ETIMEOUT-请求超时,或者可以像gamil建议改为5分钟](http:https://img.haomeiwen.com/i2628066/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>

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


















·
上一篇 下一篇

猜你喜欢

热点阅读