-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
52 lines (42 loc) · 1.04 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
import dotenv from 'dotenv';
import notifier from 'mail-notifier';
import { IncomingWebhook } from '@slack/webhook';
import { MailToSlackMsg } from './lib/mail-to-slack-msg';
// import fs from 'fs';
dotenv.config();
const ENV = process.env;
const webhook = new IncomingWebhook(ENV.SLACK_WEBHOOK_URL);
const n = notifier({
user: ENV.EMAIL,
password: ENV.PASSWORD,
host: ENV.HOST,
port: ENV.PORT,
tls: false,
tlsOptions: { rejectUnauthorized: false },
});
n.on('connected', () => console.log(`---connected---`));
n.on('mail', async (mail) => {
// fs.writeFileSync('mail.json', JSON.stringify(mail));
await webhook.send({
text: new MailToSlackMsg({
from: mail.from,
to: mail.to,
cc: mail.cc,
subject: mail.subject,
date: mail.date,
attachments: mail.attachments,
html: mail.html,
}).get(),
});
});
n.on('error', (error) => {
console.log(`---error---\n${error}`);
n.stop();
n.start();
});
n.on('end', () => {
console.log(`---disconnect---`);
n.start();
});
n.start();