Suppress Email

Add email to the Mailgun suppression list. [See the docs here](https://documentation.mailgun.com/en/latest/api-suppressions.html#suppressions)

Script mailgun Verified

by stephanemissmeshell18 ยท 6/6/2022

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 362 days ago
1
type Mailgun = {
2
  api_key: string;
3
};
4

5
export async function main(
6
  resource: Mailgun,
7
  domain: string,
8
  data: {
9
    address: string;
10
    tags: string[];
11
    created_at?: string;
12
  }[]
13
) {
14
  return (
15
    await fetch(`https://api.mailgun.net/v3/${domain}/unsubscribes`, {
16
      method: "POST",
17
      headers: {
18
        "Content-Type": "application/json",
19
        Authorization:
20
          "Basic " + Buffer.from(`api:${resource.api_key}`).toString("base64"),
21
      },
22
      body: JSON.stringify(data),
23
    })
24
  ).json();
25
}
26