0
Validate Email
One script reply has been approved by the moderators Verified

Email Address Validation is a paid service from Sendgrid and it's available to Email API Pro and Premier level accounts only.

Created by rubenmanhague 681 days ago Viewed 4113 times
0
Submitted by adam186 Deno
Verified 503 days ago
1
import sendgrid from "npm:@sendgrid/client@^7.7.0";
2

3
type Sendgrid = {
4
  token: string;
5
};
6
export async function main(
7
  api_token: Sendgrid,
8
  email: string,
9
  source?: string,
10
) {
11
  sendgrid.setApiKey(api_token.token);
12

13
  const request = {
14
    url: `/v3/validations/email`,
15
    method: "POST",
16
    body: {
17
      email,
18
      source,
19
    },
20
  };
21

22
  try {
23
    const [_, body] = await sendgrid.request(request);
24
    return body;
25
  } catch (error) {
26
    throw Error("\n" + JSON.stringify(error?.response?.body || error));
27
  }
28
}
29