-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail-api.js
More file actions
33 lines (31 loc) · 864 Bytes
/
mail-api.js
File metadata and controls
33 lines (31 loc) · 864 Bytes
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
const rp = require('request-promise')
const urljoin = require('url-join')
const config = require('config')
const create = (mail, recipients) => {
const requests = recipients.map(({ recipient, secretCode }) => {
const to = mail.to ? mail.to.value : []
const from = mail.from ? mail.from.value : []
const cc = mail.cc ? mail.cc.value : []
const bcc = mail.bcc ? mail.bcc.value : []
return rp.post({
uri: urljoin(config.url, 'api/mail/create'),
body: {
subject: mail.subject,
recipient,
secretCode,
to,
from,
cc,
bcc,
date: mail.date,
messageId: mail.messageId,
html: mail.html,
text: mail.text,
// TODO Upload attachment files and datas.
},
json: true,
})
})
return Promise.all(requests)
}
exports.create = create