1
import sendgrid from "npm:@sendgrid/mail@^7.7.0";
2
3
/**
4
* @param is_message_html If `true` then the message will be sent and parsed as HTML,
5
* otherwise it will be sent as plain text.
6
*/
7
type Sendgrid = {
8
token: string;
9
};
10
export async function main(
11
api_token: Sendgrid,
12
from: string,
13
to: string[],
14
subject: string,
15
message: string,
16
is_message_html: boolean,
17
) {
18
sendgrid.setApiKey(api_token.token);
19
const messageObject: Record<string, string | string[]> = {
20
to,
21
from,
22
subject,
23
24
messageObject[is_message_html ? "html" : "text"] = message;
25
26
try {
27
return await sendgrid.send(messageObject, true);
28
} catch (error) {
29
throw Error("\n" + JSON.stringify(error?.response?.body || error));
30
}
31
32