-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathattachments.ts
33 lines (24 loc) · 1.08 KB
/
attachments.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
import { MailtrapClient } from "mailtrap"
const TOKEN = "<YOUR-TOKEN-HERE>";
const TEST_INBOX_ID = "<YOUR-TEST-INBOX-ID-HERE>"
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>"
const client = new MailtrapClient({ token: TOKEN, testInboxId: TEST_INBOX_ID, accountId: ACCOUNT_ID });
const inboxesClient = client.testing.inboxes
const messagesClient = client.testing.messages
const attachmentsClient = client.testing.attachments
inboxesClient.getList()
.then(async (inboxes) => {
if (inboxes && inboxes.length > 0) {
const firstInboxId = inboxes[0].id
const messages = await messagesClient.get(firstInboxId)
if (messages && messages.length > 0) {
const firstMessageId = messages[0].id
const attachments = await attachmentsClient.getList(firstMessageId, firstInboxId)
if (attachments && attachments.length > 0) {
const firstAttachment = attachments[0].id
const attachmentData = await attachmentsClient.get(firstInboxId, firstMessageId, firstAttachment)
console.log(attachmentData)
}
}
}
})