-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheverything.ts
More file actions
48 lines (38 loc) · 1.43 KB
/
everything.ts
File metadata and controls
48 lines (38 loc) · 1.43 KB
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
import { MailtrapClient } from "../../src/index";
const TOKEN = "<YOUR-TOKEN-HERE>";
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>";
const client = new MailtrapClient({
token: TOKEN,
accountId: Number(ACCOUNT_ID),
});
async function sendingDomainsFlow() {
try {
// Get all sending domains
const all = await client.sendingDomains.getList();
console.log("All sending domains:", JSON.stringify(all, null, 2));
if (!all.data || all.data.length === 0) {
console.log("No sending domains found for this account.");
return;
}
// Get a specific sending domain
const one = await client.sendingDomains.get(all.data[0].id);
console.log("One sending domain:", JSON.stringify(one, null, 2));
// Send setup instructions
const setupResponse = await client.sendingDomains.sendSetupInstructions(
all.data[0].id,
"admin@example.com"
);
console.log("Setup instructions sent");
// Create a new sending domain
const created = await client.sendingDomains.create({
domain_name: "test-domain-" + Date.now() + ".com",
});
console.log("Created sending domain:", JSON.stringify(created, null, 2));
// Delete the created domain
await client.sendingDomains.delete(created.id);
console.log("Sending domain deleted");
} catch (error) {
console.error("Error in sendingDomainsFlow:", error instanceof Error ? error.message : String(error));
}
}
sendingDomainsFlow();